Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 06-17-2007, 12:10 AM   #16 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
The = operator is your friend
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 06-17-2007, 10:41 AM   #17 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Quote:
Originally Posted by teknomage1 View Post
The = operator is your friend
For what?

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 06-17-2007, 02:53 PM   #18 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
Quote:
Originally Posted by Salchester View Post
how do you put information into the array using variables
Quote:
Originally Posted by teknomage1 View Post
The = operator is your friend
there's nothing more to say about it.

P.S. Salchester, how old are you?
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 06-18-2007, 01:22 AM   #19 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Insert Table Data into Array

DJMaze,

That's It? But how do I store the data in a variable in the array like following Visual Basic code does?

The name, species, & sex variables are linked with the array on the 6th line.

Code:
Private Type details name As String species As String sex As String End Type Dim record() As details Private Sub Form_Load() ReDim record(0) End Sub Private Sub lblNext_Click() ReDim Preserve record(UBound(record) + 1) record(UBound(record)).name = txtName.Text record(UBound(record)).species = txtSpecies.Text record(UBound(record)).sex = txtSex.Text MsgBox record(1).name End Sub
Many Thanks,
P.S I'm 20 Why?
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 06-18-2007, 01:53 AM   #20 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Insert Table Data into Array

DJMaze,

The following code doesn't work, nothing gets display from the database.
Why is this?

Code:
<?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("WB", $con); $result = mysql_query("select * from Birds"); // alternatively, you could use mysql_fetch_assoc if you wanted // the array to be keyed by the field name while ($array = mysql_fetch_assoc($result)) { echo $array[0]['Name']; } ?>
Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 06-18-2007, 02:45 AM   #21 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
Well sometimes your question are like from a 12 year old in my feeling.
It's not to downgrade you, but some questions emply that you didn't learn a thing from answers due to the fact that basics like operator and associative arrays are missing in your knowledge.

PHP Code:
header('Content-type: text/plain');

$records = array();
while (
$array mysql_fetch_assoc($result))
{
    
$records[] = $array;


print_r($records); 
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 06-18-2007, 03:07 AM   #22 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
Just a quick out of thoughts rewrite of your VB thingy there into PHP, Absolutely no guarentie it will work of any sort
PHP Code:
<?

$con 
mysql_connect("localhost","peter","abc123");
if (!
$con)
{
  die(
'Could not connect: ' mysql_error());
}
mysql_select_db("WB"$con);

class 
details {
  var 
$name;
  var 
$species;
  var 
$sex;
  function 
details($id){
    
$result mysql_query("select * from Birds where id = '$id'");
    if(
$array mysql_fetch_array($result)){
      
$this->name $array['name'];
      
$this->species $array['species'];
      
$this->sex $array['sex'];
    }
  }
  function 
show(){
    echo 
"<table border=1 cellspacing=0 cellpadding=0>
    <tr><td>" 
$this->name "</td>
    <tr><td>" 
$this->species "</td>
    <tr><td>" 
$this->sex"</td></tr></table>"
  }
}

class 
record{
  var 
$items = array();
  var 
$count;
  function 
record(){
    
$this->count 0;
    
$result mysql_query("select id from Birds");
    while (
$array mysql_fetch_array($result)) {
      
$this->items[$this->count++] = new details($array['id']);
    }
  }
  function 
show(){
    for(
$i=0$i $this->count$i++)
      
$this->items[$i]->show();
  }
}

$my_record = new record();
$my_record->show();
?>
For a refference, you can look at the Object Oriented PHP article.

And DjMs question regarding your age, is of some relevence, since some of your questions seems to come from one who dosn't grasp what is going on, and feel it is easier to ask for a solution than to piece together one from previus explanations.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 06-18-2007, 03:20 AM   #23 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Insert Table Data into Array

DJMaze,

How come the following doesn't work, when code is included from previous posts?

Code:
<?php header('Content-type: text/plain'); $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("WB", $con); $result = mysql_query("select * from Birds"); $records = array(); while ($array = mysql_fetch_assoc($result)) { $records[0]['Name']; } print_r($records); ?>
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 06-18-2007, 05:25 AM   #24 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
Do you really want me to reply?
Did you ever try my code (and that from redhead and sde) ?
Did you see the output of that code?
Why did you modify my code?
Can you please read, copy and understand it all before screwing around with it?
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 06-18-2007, 08:30 AM   #25 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Insert Table Data into Array

JMaze,
Quote:
Do you really want me to reply?
Yes. Please
Quote:
Did you ever try my code (and that from redhead and SDE)?
Yes, the code I posted previously was from help by SDE, only it don't work, nothing gets displayed. Somethings wrong, but what?

As far as Redhead code goes, that doesn't work either, I keep getting greeted with the following error message.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Dale Piper\Desktop\xampplite\htdocs\Array.php on line 36
Quote:
Did you see the output of that code?
Yes. See Above
Quote:
Why did you modify my code?
The code you posted didn't include PHP opening/closing tags, nor did it declare where the data was coming from. e.g. Database, Table etc.
Quote:
Can you please read, copy and understand it all before screwing around with it?
Understanding it, come with playing around. I am a hands on person, and mucking around with things at finding out how it works etc, is the way I learn. You can change the way people learn. We all learn in different ways, at within different time frames.

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 06-18-2007, 09:16 AM   #26 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Insert Table Data into Array

DJMaze,

How come when i change the following code (In Bold)

from:
Code:
$records[] = $array;
to:
Code:
$records[1] = $array;
The the last record entered gets displayed as record 0 in stead of the second record being displayed?
Code:
<?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("WB", $con); $result = mysql_query("select * from Birds"); header('Content-type: text/plain'); $records = array(); while ($array = mysql_fetch_assoc($result)) { $records[0] = $array; } print_r($records); ?>
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 06-18-2007, 09:42 AM   #27 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
Quote:
Code:
$records[0] = $array;
You are overwriting index '0' of your array constantly, look at DjM code, it is not indexing a specific location when adding to the array.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 06-18-2007, 10:35 AM   #28 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
Quote:
Originally Posted by Salchester View Post
As far as Redhead code goes, that doesn't work either, I keep getting greeted with the following error message.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Dale Piper\Desktop\xampplite\htdocs\Array.php on line 36
That one is easy to debug.
PHP Code:
$result mysql_query("select * from Birds");
if (!
$result) { die(mysql_error()); } 
And i want you to tell me what this code does, step by step.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 06-18-2007, 10:54 AM   #29 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Insert Table Data into Array

Quote:
Originally Posted by redhead View Post
You are overwriting index '0' of your array constantly, look at DjM code, it is not indexing a specific location when adding to the array.
Redhead,

How do I change it so it does index a specific location when adding an entry to the array?

Resulting in each record (Name,Species, Sex) having its own location within the array, starting at 0.

This will be useful as I will need it for later.

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 06-19-2007, 05:18 AM   #30 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
Quote:
Originally Posted by Salchester View Post
JThe code you posted didn't include PHP opening/closing tags, nor did it declare where the data was coming from. e.g. Database, Table etc.Understanding it, come with playing around. I am a hands on person, and mucking around with things at finding out how it works etc, is the way I learn. You can change the way people learn. We all learn in different ways, at within different time frames.
It didn't have open/close tags because it shouldn't need that at all.
If you did compare codes, you would have noticed my code was just a portion of all the code.

Sorry but it looks like your way of learning stuff is bad. You haven't learn a thing so far.
If you did, tell me what you have learned, code line by code line. Else i don't see any use of replying to you again and again and again by any of us.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Table data from db as new form input tomycon PHP 2 03-03-2006 05:26 AM
Input File Data Into Array in C++? wizardman Standard C, C++ 1 09-02-2005 11:15 PM
How to insert HTML form data into mysql database ? plomon PHP 5 02-06-2005 08:23 AM


All times are GMT -8. The time now is 05:06 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle