Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP while-loop not working with mysql_result
    primarykey
    data
    text
    <p>I have a Physician Query:</p> <pre><code>// Primary Physician Query $qPhysician = mysql_query("SELECT * FROM physicians ORDER BY lastName ASC, firstName ASC"); $rowPhysician = mysql_fetch_array($qPhysician); // State Query for Physician $idStatePhysician = $rowPhysician['idstate']; $qStatePhysician = mysql_query("SELECT * FROM states WHERE idstate=$idStatePhysician"); $rowStatePhysician = mysql_fetch_array($qStatePhysician); // City Query for Physician $idCityPhysician = $rowPhysician['idcity']; $qCityPhysician = mysql_query("SELECT * FROM cities WHERE idcities=$idCityPhysician"); $rowCityPhysician = mysql_fetch_array($qCityPhysician); </code></pre> <p>I have a while loop to display all physicians row to a table:</p> <pre><code>$num = mysql_num_rows($qPhysician); $i=0; while($i &lt; $num) { $idphysicians = $rowPhysician['idphysicians']; if ($i % 2 == 0){ echo "&lt;tr class='even' onclick=\"DoNav('physicianUpdate.php?idphysicians=$idphysicians');\"&gt;"; } else{ echo "&lt;tr class='odd' onclick=\"DoNav('physicianUpdate.php?idphysicians=$idphysicians');\"&gt;"; } echo "&lt;td&gt;" . mysql_result($qPhysician,$i,"lastName") . "&lt;/td&gt;"; echo "&lt;td&gt;" . mysql_result($qPhysician,$i,"firstName") . "&lt;/td&gt;"; echo "&lt;td&gt;"; if(isset($rowPhysician['idcity'])){echo mysql_result($qCityPhysician,$i,"name");} else{} echo "&lt;/td&gt;"; $i++; } </code></pre> <p>My problem is: I have 3 rows of data from my physicians table. Each has a value for 'idcity' reflecting the idnumber from my City table. However, the 1st row of Data displays the idcity=Name properly, but the 2nd and 3rd row gave an error:</p> <pre><code>Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 7 in C:\wamp\www\iPOC\physicians.php on line 55 </code></pre> <p>Also, if I have a blank value for idcity on one of the row, it also generates an error.</p> <p>Please help! Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload