-1

I’m working on a php page and I want to display usernames according to a parameter that we’ll call h. So basically, I want to take all the ids from an sql database where h="x" but when I use my code only the first row gets fetched to the array:

$query = "Select id from $usertable where hschool='$hschool'";
$Mquery = mysql_query($counting);
$Array = mysql_fetch_array($counting);

I’ll appreciate all the help you can give me!

0

5 Answers 5

1

Solution:

   try this php code:

    <?php



         $Mquery = mysql_query("Select * from $usertable where hschool='$hschool'");

         while($row = mysql_fetch_array($Mquery))
               {
                  echo row[id];//This will display all the row id's.
               }

    ?>

Here row[place column name here] place the column name inside the row[] which will give you the column value for all the rows.

Hope it will work.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to loop through it to retreive all the data:

    $query = "Select id from $usertable where hschool='$hschool'";
    $Mquery = mysql_query($counting);
    $ids = Array();
    while( $Array = mysql_fetch_array($Mquery)) {
        // $Array will contain 1 row
        $ids[] = $Array['id'];
    }

1 Comment

Thank you, this does return the values but how can I make them to be so ? Array[0] => ID 1 Array[1] => ID 2 ?
0
while($Array = mysql_fetch_array($Mquery)){
  echo $Array['f'];
}

Comments

0

mysql_fetch_array() returns one row at a time. So you will have to do something like,

while($Array = mysql_fetch_array($Mquery)){
    //Use $Array here
}

Comments

0
enter code here

we cannot call the spacefic id because it return one row or duplication of the raw

$query = "Select * from username ";
$Mquery = mysql_query($query);
while( $Array = mysql_fetch_array($Mquery)) {
    // $Array will contain number of row
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.