Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Querying tables in php

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
When i try to insert a record and select the same record
immeidiately from the table it doesn't display the first record.
When i insert the second record i'm able to select the second record.But the first record is not displayed.

Step1:Trying to insert a record using this statements
$query = "insert into cd_order values ( '".$date_added ."','".$session ."','".$cd_title ."')";
$result = mysql_query($query);

Step2:Trying to selct the same record
$result = mysql_query( "SELECT cd_title frOM cd_order where session='$session' ");
$row = mysql_fetch_array($result);
$num_results = mysql_num_rows($result);

Step3:Trying to display the records in a table format which displays all the records other than the first record
for ($i=0 ;$i <= $num_results -1; $i++)
{
$row = mysql_fetch_array($result);
{
echo &quot;<TR><TD >&quot; .$row[cd_title]. &quot;</TD>\n&quot;;
}
}

Hope someone will help with the solution.
 
Try to use this kind of insertion query:

$query = &quot;insert into cd_order (date_added,session,cd_title)values ( '&quot;.$date_added .&quot;','&quot;.$session .&quot;','&quot;.$cd_title .&quot;')&quot;;

Specifying the column names mostly does the trick.

Hope to have been of some useful assistance,
Stijn Teijssen
 
Correction of previous post:

$query = &quot;insert into cd_order (date_added,session,cd_title)values ( '$date_added','$session','$cd_title')&quot;;

You don't need the '&quot;.$date_added.&quot;' structure

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top