GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Aug-2004, 07:55
hellcat1 hellcat1 is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Spring, TX
Posts: 7
hellcat1 is on a distinguished road
Question

Problems pulling data from table


I'm a little baffled as to why my PHP is not pulling all my data it should from MySQL. Here is my situation.

PHP Code:

$connection2 = mysql_connect("localhost", "hellcat1", "**********") or die ('I cannot connect to the database because: ' . mysql_error()); 
mysql_select_db("automaint", $connection2);

echo "username = ".$username."<br>";
$result2 = mysql_query("SELECT * FROM automaint.vehicles WHERE username='$username'");
$myrow2 = mysql_fetch_array($result2);
echo "result2 = <br>";
print_r($myrow2);
echo "<br>"; 



Here is what table automaint.vehicles contains

id username vehicle
1 hellcat1 2001 Chevrolet S10
2 hellcat1 2001 Dodge Ram 1500
3 hellcat1 1985 Chevrolet S10 Blazer
4 hellcat1 1987 GMC S15

Here is the results

username = hellcat1
result2 =
Array ( [0] => 1 [id] => 1 [1] => hellcat1 [username] => hellcat1 [2] => 2001 Chevrolet S10 [vehicle] => 2001 Chevrolet S10 )

Any ideas why it's only pulling the first row and stopping?
Last edited by JdS : 01-Aug-2004 at 08:48. Reason: Please insert [php] & [/php] tags between your example PHP codes
  #2  
Old 01-Aug-2004, 08:51
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
You need to loop through the results/resource ($result2)...

PHP Code:

// snipped php code...
while( $myrow2 = mysql_fetch_array($result2) )
{
  echo "result2 = <br>";
  print_r($myrow2);
  echo "<br>";
}
// snipped php code... 


  #3  
Old 01-Aug-2004, 09:31
hellcat1 hellcat1 is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Spring, TX
Posts: 7
hellcat1 is on a distinguished road
Talking

Quote:
Originally Posted by JdS
You need to loop through the results/resource ($result2)...

PHP Code:

// snipped php code...
while( $myrow2 = mysql_fetch_array($result2) )
{
  echo "result2 = <br>";
  print_r($myrow2);
  echo "<br>";
}
// snipped php code... 



Great, I changed the code to
PHP Code:

$result2 = mysql_query("SELECT * FROM automaint.vehicles WHERE username='$username'");
$vehicleoptions = "<select name=\"vehicles\">";
while( $myrow2 = mysql_fetch_array($result2) ) 
{ 
  $vehicleoptions .= "<option value=\"".$myrow2[vehicle]."\">".$myrow2[vehicle]."</option>";
}
$vehicleoptions .= "</select>";
echo "<br>"; 



And now I'm dynamically building a select box for entering data.
  #4  
Old 01-Aug-2004, 10:00
conkermaniac conkermaniac is offline
Member
 
Join Date: Dec 2001
Location: China
Posts: 174
conkermaniac is on a distinguished road
Aha, I see what you're doing there. All set to go?

Conker
__________________
You're not supposed to be looking at this.
  #5  
Old 01-Aug-2004, 10:17
hellcat1 hellcat1 is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Spring, TX
Posts: 7
hellcat1 is on a distinguished road
Exclamation

Quote:
Originally Posted by conkermaniac
Aha, I see what you're doing there. All set to go?

Conker

For that issue yes. Now I'm trying to figure the best way to display the data stored in automaint.oil for a user with multiple vehicles (as seen in the above select box).

Ideally, I would like to display each vehicles of $username in automaint.vehicles in it's own table with all instances from automaint.oil listed like this.

Your Oil Change History
as you previously entered on this site.
User Name : hellcat1
Date Of Change Vehicle Filter Used Oil Type and Amount Used Milage Changed
January 05, 2004 2001 Chevrolet S10 Napa Gold FIL1036 5 Qts of Standard Oil 48000
April 04, 2004 2001 Chevrolet S10 AC Delco PF52 5 Qts of Full Synthetic 51000
July 30, 2004 2001 Chevrolet S10 AC Delco PF52 5 Qts of Full Synthetic 55157
Next Oil Change Due On October 30, 2004 Or @ 60157 Miles.
Edit Your Data Submit New Data
Attached Images
File Type: jpg vehicleoilchangetable.jpg (54.8 KB, 3 views)
  #6  
Old 03-Aug-2004, 09:08
conkermaniac conkermaniac is offline
Member
 
Join Date: Dec 2001
Location: China
Posts: 174
conkermaniac is on a distinguished road
If you're looking to put the data into table format, you can use echo statements within the while loop (after executing the query) to generate the table.

Conker
__________________
You're not supposed to be looking at this.
  #7  
Old 03-Aug-2004, 20:23
hellcat1 hellcat1 is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Spring, TX
Posts: 7
hellcat1 is on a distinguished road
Talking

Quote:
Originally Posted by conkermaniac
If you're looking to put the data into table format, you can use echo statements within the while loop (after executing the query) to generate the table.

Conker
I've already got it up and working.
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 15:13
Search data in table. eRIC MySQL / PHP Forum 2 16-May-2004 03:06
some I/O problems...again cameron CPP / C++ Forum 3 03-Mar-2004 21:39
Automate a data change php form mjfmn MySQL / PHP Forum 4 20-Oct-2003 09:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:57.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.