Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Accessing arrays from MySQL Query using PHP

Featured Replies

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 -

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

  • 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 -

  • 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 -
  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.