Jump to content

Recommended Posts

It's been a while since i looked at php and SQL nad my head is hoping at the minute...

 

I know this isnt to hard but how do i turn returned results into an array if my query is as follows

 

$getData = mysql_query('SELECT * FROM name');

$result = mysql_query($getData);

 

Thanks for you help

Link to comment
https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/
Share on other sites

$getData = mysql_query('SELECT * FROM name');
while ($result = mysql_fetch_assoc($getData))
{
echo $result['fieldname'] . "<br />";
}

 

I get the following errors

 

mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

 

I am using XAMPP on my local machine to test

Have you actually opened a connection to mysql?

Show us all your code.

 

 

Heres my code

 

 <?php
$con = mysql_connect("localhost","pagination","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


$rowData = array();
$getData = mysql_query('SELECT * FROM test');
while ($rowData = mysql_fetch_assoc($getData))
{
echo $rowData['name'] . "<br />";
}                                                

    // Include the pagination class
    include 'pagination.class.php';
    // Create the pagination object
    $pagination = new pagination;
    // parse the data
    $dataPages = $pagination->generate($rowData, 20);

    foreach ($dataPages as $dataKey => $dataArray) {
    // Show the information about the item
    echo '<p><b>'.$dataArray['fieldname'].'</b> '.$dataArray['fieldname2'].'</p>';
    } 

      ?>

You have an erro in your sql query if your are getting that error, what does the following return:

$query = 'SELECT * FROM name';
$getData = mysql_query($query) or die('SQL Query Error: ' . mysql_error() . '<br />Query: <pre>' . $query . '</pre>');
while ($result = mysql_fetch_assoc($getData))
{
    echo $result['fieldname'] . "<br />";
}

You have an erro in your sql query if your are getting that error, what does the following return:

$query = 'SELECT * FROM name';
$getData = mysql_query($query) or die('SQL Query Error: ' . mysql_error() . '<br />Query: <pre>' . $query . '</pre>');
while ($result = mysql_fetch_assoc($getData))
{
    echo $result['fieldname'] . "<br />";
}

 

Came back with

 

SQL Query Error: No database selected

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.