stmosaic Posted March 19, 2018 Share Posted March 19, 2018 I know this is probably so easy I can't see it, but I'm going from PHP 5 to 7 and having to modify my existing pages. Been working on this for 2 days and am hopelessly confused. I used to put the query results into the PHP variables like $IDENT & $NAM to be used further down in my while loop. $dbcnx is the db connection that works and $sql is the SELECT statement further up the code and it works. No errors, but no data either. Now, I'm not sure how to do that without getting horridly complicated. This needs to be as simple and straight forward as possible, due to my health. ///===DISPLAY ALL LISTINGS===/// //// $result2 = mysqli_query($dbcnx,$sql); $i=0; while ($row = $result2->fetch()) { $IDENT=$row["ID"]; $NAM=$row['dcategory']; //the variables above are used later in the table to display query results. //===ALTERNATING ROW COLORS===// $i++; if ($i % 2) { $bgc="FFCC00"; } else { $bgc="FFFF00"; } //===END ALTERNATING ROW COLORS===// //===DISPLAY ALL LISTINGS===// echo" <tr bgcolor=\"#$bgc\"> <td width=\"9%\"> <div align=\"center\"><input type=\"text\" size=\"3\" maxlength=\"3\" value=\"$IDENT\"> <input type=\"hidden\" name=\"Ident[]\" value=\"$IDENT\"></div> </td> <td width=\"45%\"> <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=2>$NAM</font></div> </td> <td width=\"13%\"> <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=2> <a href=\"CAT_edit_form.php?ID=$IDENT\"><img src=\"$SCIMAGEPATH/modify.gif\" border=0></a></font></div> </td> <td width=\"16%\"><div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=2><a href=\"CAT_delete.php?DEL=Y&ID=$IDENT\"><img src=\"$SCIMAGEPATH/delete.gif\" border=\"0\"></a></font></div> </td> </tr> "; } Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 19, 2018 Share Posted March 19, 2018 there is no mysqli result ->fetch() method. you would be seeing a php runtime error to alert you to the problem if you set php's error_reporting to E_ALL and display_errors to ON. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 19, 2018 Share Posted March 19, 2018 Try this while ($row = $result2->fetch_assoc()) Plus, you need to escape the content to prevent XSS and general display issues with certain content $IDENT = htmlentities($row["ID"], ENT_QUOTES); $NAM = htmlentities($row['dcategory'], ENT_QUOTES); Also, replace the alternating color code with just this //===ALTERNATING ROW COLORS===// $i++; $bgc = ($i % 2) ? 'FFCC00' : 'FFFF00'; //===END ALTERNATING ROW COLORS===// Plus, get rid of the font tags and use proper CSS. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.