February 26, 201412 yr Hello, I have created a MySQL query which gets the relevant fields from my database. I then want to put the results into an array which I can then call from. This is what I have so far: $homeqry = "SELECT j.ISSN, j.Title As 'Journal Title', i.Volume, i.Issue, i.Status, i.DeliveryDeadline As 'Deadline' FROM tbl_jv_journals j, tbl_jv_issues i WHERE j.ClientID = {$_SESSION['clientid']}" or die(mysql_error()); $homeres = mysql_query($homeqry); Later on I then have this code in php: Print "<b>ISSN:</b> ".$homeres['ISSN'] . " "; The query itself works fine. The trouble arises when I use this line: $homeres = mysql_query($homeqry); When debugging it was coming back as false. I cannot understand what it is I have done wrong. And because of this I am unable to actually print anything with the php code used later on. Help will be highly appreciated. - MjA -
February 26, 201412 yr look into mysql_fetch_array() $query = mysql_query("SELECT * FROM customers"); while ($row = mysql_fetch_array($query)) { echo $row['customerName'].'<br />'; } or even better have a look at PDO as mysql_* is being depricated
February 27, 201412 yr Author I implemented what you have posted and I receive this particular error. Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean Do you know why this could be happening? - MjA -
February 27, 201412 yr Author Here is the exact code that I have. Is there any reason the error should be coming up. <?php $query = mysql_query("SELECT j.ISSN, j.Title As 'Journal Title', i.Volume, i.Issue, s.StatusName As 'Status', i.DeliveryDeadline As 'Deadline' FROM tbl_jv_journals j, tbl_jv_issues i, restblbookstatus s WHERE s.StatusID = i.Status AND j.ClientID = ' " . addslashes($_SESSION['clientid']) . " ' "); while ($row = mysql_fetch_array($query)) { echo $row['ISSN'].'<br />'; } ?> I ran the query in Workbench (MySQL DB Management System) and it works fine. However when I run it in PHP I get the value of $query coming back as false. - MjA -
February 28, 201412 yr Author I incorporated what I learned from your script and I have now got it working. Thank you for your help. - MjA -
Create an account or sign in to comment