lokie538 Posted April 14, 2008 Share Posted April 14, 2008 Hi, With this code im trying to get the output in a table. But I keep getting this error: Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\4\review.php on line 19 <?php include("checkloginstatus.php"); $host = $_SESSION['host']; $user = $_SESSION['user']; $passwd = $_SESSION['passwd']; $dbname = "ppss"; $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("User name or password is wrong."); $query = "SELECT Given_Names, Family_Name, Roll_class, Date_Enrolled, T.ContactDate From studePE1 S, TIEnrolmentReview T WHERE S.Student_ID=T.StudentID ORDER BY 4 ASC"; $result = mysqli_query($cxn,$query) or die ("Couldnt execute query."); $num = mysqli_num_rows($result); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $Given_Names=mysql_result($result,$i,'Given_Names'); $Family_Name=mysql_result($result,$i,"Family_Name"); $Roll_class=mysql_result($result,$i,"Roll_class"); $Date_Enrolled=mysql_result($result,$i,"Date_Enrolled"); $ContactDate=mysql_result($result,$i,"ContactDate"); echo "<b> $Given_Names $Family_Name</b><br>$Roll_class<br>$Date_Enrolled<br>$ContactDate<hr><br>"; $i++; } mysql_error() ?> Do you know whats wrong as Ive never used the mysql_result function before? Thanks in advance Quote Link to comment Share on other sites More sharing options...
sasa Posted April 14, 2008 Share Posted April 14, 2008 are you use mysql or mysqli Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 14, 2008 Share Posted April 14, 2008 Using a counter to retrieve records is a poor choice anyway. Use a while loop with one of the mysql_fetch_ functions. Also, no need to copy all the results into variables just to use those variables once. <?php include("checkloginstatus.php"); $host = $_SESSION['host']; $user = $_SESSION['user']; $passwd = $_SESSION['passwd']; $dbname = "ppss"; $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("User name or password is wrong."); $query = "SELECT Given_Names, Family_Name, Roll_class, Date_Enrolled, T.ContactDate From studePE1 S, TIEnrolmentReview T WHERE S.Student_ID=T.StudentID ORDER BY 4 ASC"; $result = mysqli_query($cxn,$query) or die (mysql_error()); echo "<b><center>Database Output</center></b><br><br>"; while ($row = mysql_fetch_assoc($result)){ echo "<b> " . $row['Given_Names'] . " " . $row['Family_Name'] . " </b><br>" . $row['Roll_class'] . "<br>" . $row['Date_Enrolled'] . "<br>" . $row['ContactDate'] . "<hr><br>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
lokie538 Posted April 14, 2008 Author Share Posted April 14, 2008 are you use mysql or mysqli im using php 5.2.5 so i dunno which do i have to use? Quote Link to comment Share on other sites More sharing options...
lokie538 Posted April 14, 2008 Author Share Posted April 14, 2008 Using a counter to retrieve records is a poor choice anyway. Use a while loop with one of the mysql_fetch_ functions. Also, no need to copy all the results into variables just to use those variables once. Now im getting a Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource error?? Is there something wrong with my query as it works in phpmyadmin?? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2008 Share Posted April 14, 2008 The original code and the "fixed" code are both mixing a mysqli query with a mysql_fetch_xxxxx, which is what is causing the error. Pick mysqli or mysql. Don't mix them. Quote Link to comment Share on other sites More sharing options...
lokie538 Posted April 14, 2008 Author Share Posted April 14, 2008 The original code and the "fixed" code are both mixing a mysqli query with a mysql_fetch_xxxxx, which is what is causing the error. Pick mysqli or mysql. Don't mix them. Sorry if I sound stupid but what's the difference? between mysqli and mysql Quote Link to comment Share on other sites More sharing options...
lokie538 Posted April 14, 2008 Author Share Posted April 14, 2008 Yup its working now with this code: <?php include("checkloginstatus.php"); $host = $_SESSION['host']; $user = $_SESSION['user']; $passwd = $_SESSION['passwd']; $dbname = "ppss"; $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("User name or password is wrong."); $query = "SELECT Given_Names, Family_Name, Roll_class, Date_Enrolled, T.ContactDate From studePE1 S, TIEnrolmentReview T WHERE S.Student_ID=T.StudentID ORDER BY 4 ASC"; $result = mysqli_query($cxn,$query) or die ("Couldnt execute query."); $num = mysqli_num_rows($result); echo "<b><center>Database Output</center></b><br><br>"; while ($row = mysqli_fetch_assoc($result)){ echo "<b> " . $row['Given_Names'] . " " . $row['Family_Name'] . " </b><br>" . $row['Roll_class'] . "<br>" . $row['Date_Enrolled'] . "<br>" . $row['ContactDate'] . "<hr><br>\n"; } ?> Thanks everyone 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.