Wildhalf Posted April 3, 2008 Share Posted April 3, 2008 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 More sharing options...
discomatt Posted April 3, 2008 Share Posted April 3, 2008 mysql_fetch_assoc() or mysql_fetch_row() Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508779 Share on other sites More sharing options...
papaface Posted April 3, 2008 Share Posted April 3, 2008 $getData = mysql_query('SELECT * FROM name'); while ($result = mysql_fetch_assoc($getData)) { echo $result['fieldname'] . "<br />"; } Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508780 Share on other sites More sharing options...
Wildhalf Posted April 3, 2008 Author Share Posted April 3, 2008 $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 Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508787 Share on other sites More sharing options...
papaface Posted April 3, 2008 Share Posted April 3, 2008 Have you actually opened a connection to mysql? Show us all your code. Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508791 Share on other sites More sharing options...
marcus Posted April 3, 2008 Share Posted April 3, 2008 $getData = mysql_query("SELECT * FROM `name`") or die(mysql_error()); while($result = mysql_fetch_assoc($getData)){ echo $result['fieldname'] . "<br>\n"; } error checking. Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508792 Share on other sites More sharing options...
Wildhalf Posted April 3, 2008 Author Share Posted April 3, 2008 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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508793 Share on other sites More sharing options...
wildteen88 Posted April 3, 2008 Share Posted April 3, 2008 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 />"; } Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508795 Share on other sites More sharing options...
Wildhalf Posted April 3, 2008 Author Share Posted April 3, 2008 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 Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508798 Share on other sites More sharing options...
Wildhalf Posted April 3, 2008 Author Share Posted April 3, 2008 got database connection sorted just going to check original code now... Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508802 Share on other sites More sharing options...
Wildhalf Posted April 3, 2008 Author Share Posted April 3, 2008 After getting connection problems solved i figured out what was wrong with the rest of the code... Link to comment https://forums.phpfreaks.com/topic/99432-solved-creating-an-array/#findComment-508812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.