Jump to content

[SOLVED] getting results from mysql


vampke

Recommended Posts

Hi peoples,

 

I 'm writing a script where i want to get all the numbers out of a database and put them in an html

this is the database table:

unid  id  un1  un2  un3  un4  un5  un6  un7

1 1 2 3 8 19 48 52 63

2 1 2 3 8 20 21 43 58

3 2 1 7 11 23 26 33 44

4 2 3 12 17 42 49 71 96

5 3 21 28 38 39 47 54 59

6 3 1 4 9 19 35 42 95

 

my php code:

 

$msg ="";
$get_numbers = mysql_query("SELECT * FROM numbers");

while($row = mysql_fetch_row($get_numbers))
{
    $userid  = $row[0];
    $id      = $row[1];
    $number1 = $row[2];
    $number2 = $row[3];
    $number3 = $row[4];
    $number4 = $row[5];
    $number5 = $row[6];
    $number6 = $row[7];
    $number7 = $row[8];

    $msg .= "$number1, $number2, $number3, $number4, $number5, $number6, $number7 \n";

}

 

This returns 189 lines of results.

Here are the first few:

 

2, 3, 8, 19, 48, 52, 63

userID: 1

2, 3, 8, 19, 48, 52, 63

2, 3, 8, 20, 21, 43, 58

userID: 2

2, 3, 8, 19, 48, 52, 63

userID: 1

2, 3, 8, 19, 48, 52, 63

2, 3, 8, 20, 21, 43, 58

1, 7, 11, 23, 26, 33, 44

 

etc...

 

Can someone explain to me what i'm so obviously doing wrong?

I only want to return the 6 rows in the mysql table

 

Link to comment
Share on other sites

<?php
$msg ="";
$get_numbers = mysql_query("SELECT * FROM numbers") or die(mysql_error());

while($row = mysql_fetch_array($get_numbers))
{
    $userid  = $row[0];
    $id      = $row[1];
    $number1 = $row[2];
    $number2 = $row[3];
    $number3 = $row[4];
    $number4 = $row[5];
    $number5 = $row[6];
    $number6 = $row[7];
    $number7 = $row[8];

    $msg .= "$number1, $number2, $number3, $number4, $number5, $number6, $number7 \n";

}?>

Link to comment
Share on other sites

mysql_fetch_row() fetches one row of data while mysql_fetch_array() can fetch more than 1.

 

Since when? mysql_fetch_array fetches one row each time it is called then moves the internal pointer forward.

Oh okay. Thanks. Why do people say 'internal pointer'? ???

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.