PHP - For($i=0;$i<$rownum;$i++)
I need this script to go through each row of the mysql db and update the cat_num colum (for each record) with the new value. But this doen't seem to work.
$marks = '25'; // this value is ever changing. For this example I'll put as 25 $query=mysql_query("SELECT * FROM table1"); $rownum=mysql_num_rows($query); for($i=0;$i<$rownum;$i++) { $query=mysql_query("SELECT * FROM table1 LIMIT $i,1"); while($select=mysql_fetch_array($query)) { $update=mysql_query("UPDATE table2 SET cat_num='$select[cat_num]'+$marks"); } } Similar TutorialsI have a table and the following code. Im not sure if im using rownum in the correct way as im not getting the result expected. $result = mysql_query("SELECT * FROM totem_ads"); $num_rows = mysql_num_rows($result); $random_row = rand(1, $num_rows); $ad_sql = mysql_query("SELECT * FROM totem_ads WHERE rownum='$random_row'"); while($row_advert = mysql_fetch_array($ad_sql)) { echo "<a href='" . $row_advert['link'] . "'><img src=$img_loc'" . $row_advert['image'] . "' alt='" . $alt_text['image'] . "'></a>"; } THe ad_sql displays as expected SELECT * FROM totem_ads WHERE rownum='1' however the while loop displays nothing which makes me wonder if im using rownum incorrectly. When i search for information on rownum I find all kinds of confusin statements from people posting in forums with problems and not the correct answer im looking for. |