Jump to content

Recommended Posts

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>
If your pulling multiple values from a table you could through the query in a loop like:

[code]
// 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 />";
}
[/code]

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

Through your whole table. You would also retrieve the other fields via $row['whateverfieldnameis']
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.