Jump to content

[SOLVED] How would I do this?


Sobbs

Recommended Posts

You'll need to learn the following mysql commands.

 

mysql_connect();

mysql_select_db();

mysql_query();

mysql_fetch_assoc(); (there are multiple choices in for this command. E.g. mysql_fetch_row(), mysql_fetch_arrray() - They all do pretty much the same job though.)

 

<?php

$databaseConnection = mysql_connect( SERVER, USER, PASS ) or die( "Could not connect");
mysql_select_db( DATABASE, $databaseConnection ) or die( "Could not select the database" );

$queryResults = NULL;
$theSQL= "SELECT * FROM <table>"; // * should never really be used, however as I do not know what columns you have I did it for simplicity.
$theQuery = mysql_query( $theSQL, $databaseConnection ) or die( mysql_error() );

while( $resultRow = mysql_fetch_assoc( $theQuery ) )
{
   $queryResults[ count( $queryResults) ] = $resultRow; // place the contents of the row inside our results variable. Incrementing its key by 1.
}

var_dump( $queryResults );
?>

 

Read up on these commands and others at http://uk2.php.net/manual/en/book.mysql.php.

 

Oops, and like Kevin said, use LIMIT in your query!

 

Hope this helps! :)

Ive tried to find a tutorial on this, but non worked the way i needed it to.

 

Probably because you've skipped learning the basics and hence cannot adapt examples to your needs. There's a basic database handling tutorial on our main site. I suggest you read it and go from there.

Archived

This topic is now archived and is closed to further replies.

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