Jump to content


Photo

Trouble echoing multiple variables from the same table


  • Please log in to reply
3 replies to this topic

#1 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 07 June 2006 - 05:04 PM

Hello!

I am trying to echo multiple values from the same table, which are identified by an ID field. The data makes it into the db, and it works fine when I echo the ID rather than the gear, but when I try to echo the gear, it displays blank. Any ideas?

$sqlquery = "INSERT INTO bike VALUES('', '". $_POST['first_gear_id'] ."', '". $_POST['second_gear_id'] ."', '". $_POST['third_gear_id'] ."', '". $_POST['fourth_gear_id'] ."', '". $_POST['fifth_gear_id'] ."')";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query 1!");

$sqlquery = "SELECT * from bike";

$get_gear_info = mysql_query("SELECT * FROM gear_ratios WHERE gear_id = '".$_POST['first_gear_id']."'");
$row=mysql_fetch_array($get_gear_info);
$first_gear_id = $row['first_gear_id'];

echo'
<tr>
<td>First Gear</td>
<td>' .$first_gear. '</td>
</tr>

$get_gear_info = mysql_query("SELECT * FROM gear_ratios WHERE gear_id = '".$_POST['second_gear_id']."'");
$row=mysql_fetch_array($get_gear_info);
$second_gear_id = $row['second_gear_id'];

echo'
<tr>
<td>First Gear</td>
<td>' .$second_gear. '</td>
</tr>

#2 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 07 June 2006 - 05:59 PM

If your pulling multiple values from a table you could through the query in a loop like:

// Select all rows in the database
$get_gear_info = mysql_query("SELECT * FROM gear_ratios");

// Loop through the rows and output them
while($row = mysql_fetch_array($get_gear_info)) {
   echo "ID {$row['gear_id']} <br />";
}

Then it would output:
ID 1
ID 2
ID 3
.
.
.

Through your whole table. You would also retrieve the other fields via $row['whateverfieldnameis']


#3 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 07 June 2006 - 06:58 PM

Thank you, I'll give it a try!

#4 xyph

xyph
  • Staff Alumni
  • Advanced Member
  • 3,712 posts
  • LocationSurrey, BC

Posted 07 June 2006 - 08:27 PM

Also it might help to note that the variable '$first_gear' and '$second_gear' are echoed, yet never defined.
Everything you need to know about storing user-names and passwords
http://www.openwall....Users-Passwords
Blank Page? Try forcing errors to display
ini_set('display_errors',1);
error_reporting(-1);




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users