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 Link to comment https://forums.phpfreaks.com/topic/101002-solved-mysql_result-not-working/ Share on other sites More sharing options...
sasa Posted April 14, 2008 Share Posted April 14, 2008 are you use mysql or mysqli Link to comment https://forums.phpfreaks.com/topic/101002-solved-mysql_result-not-working/#findComment-516507 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/101002-solved-mysql_result-not-working/#findComment-516510 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? Link to comment https://forums.phpfreaks.com/topic/101002-solved-mysql_result-not-working/#findComment-516513 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?? Link to comment https://forums.phpfreaks.com/topic/101002-solved-mysql_result-not-working/#findComment-516515 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. Link to comment https://forums.phpfreaks.com/topic/101002-solved-mysql_result-not-working/#findComment-516517 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 Link to comment https://forums.phpfreaks.com/topic/101002-solved-mysql_result-not-working/#findComment-516519 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 Link to comment https://forums.phpfreaks.com/topic/101002-solved-mysql_result-not-working/#findComment-516522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.