Jump to content

[SOLVED] How to read mysql off as an array?


ted_chou12

Recommended Posts

Do you mean row as an array, or all as a multidimensional, hmmm me thinks not... (i'd like it too!)

mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both

mysql_fetch_assoc — Fetch a result row as an associative array

mysql_fetch_object — Fetch a result row as an object

mysql_fetch_row — Get a result row as an enumerated array

http://uk3.php.net/manual/en/ref.mysql.php

Link to comment
Share on other sites

Sorry, I wasnt clear, I want to read off each row as an array, and the elements of each row are elements of the array, therefore, a mutidimensional array:

so:

$read = mysql_query("SELECT * FROM forum WHERE threadid='$threadid' ORDER BY id");

I want to echo out elements in the 15th row, how should I do that?

Link to comment
Share on other sites

Something like this, probably.

 

<?php

$sql = "SELECT * FROM table";
$result = mysql_query($sql);

$table = Array();

while($row = mysql_fetch_assoc($result))
{
  $table[] = $row;
}

print_r($table[4]); // displays the fourth (or fifth?) row of the table

?>

 

I would suggest against this, though.  You're going to waste a lot of time and memory loading all the sql results into an array.  Just grab them as you need them.

Link to comment
Share on other sites

I can't use the row function because I am not pointing to a specific row, however, I am ordering them first and then find the row number that I want in relation to the other rows, so for eg. the row i want is 15th, the id for that row may not necessary be 15, so the row function wouldnt work.

Thanks.

Link to comment
Share on other sites

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.