PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm trying to get information from the "Users" table. I can connect to the "Login" table (which is in the same database) without a problem, so I don't think it's a connectivity issue.
$dbh = mysql_connect ("localhost", "user", "password") or die ('Database Connection Error: ' . mysql_error());
mysql_select_db ("database");
$queryadmin = "SELECT * FROM Login WHERE name='$name' AND admin='-1'";
$sqladmin = mysql_query($queryadmin);
$countadmin = mysql_num_rows($sqladmin);
if ($countadmin == 1) //Checks to see if you're an Administrator
{
$querymem = "SELECT * FROM Users"; //Gets all the records from the "User" table
$sqlmem = mysql_query($querymem);
echo "<select size='1' name='number'>";
while ($row = mysql_fetch_array($sqlmem))
{
$option = $option."<option value=".$row['number'].">".$row['number']."</option>"; //Should go through every record getting the "number"
}
echo $option;
echo "</select>";
}
I'm using the same code on another page but refering to the "Login" table and it works without a problem.
Last edited by LuiePL on Tue Aug 08, 2006 5:22 pm, edited 1 time in total.
LuiePL wrote:I'm trying to get information from the "Users" table. I can connect to the "Login" table (which is in the same database) without a problem, so I don't think it's a connectivity issue.
$dbh = mysql_connect ("localhost", "user", "password") or die ('Database Connection Error: ' . mysql_error());
mysql_select_db ("database");
$queryadmin = "SELECT * FROM Login WHERE name='$name' AND admin='-1'";
$sqladmin = mysql_query($queryadmin);
$countadmin = mysql_num_rows($sqladmin);
if ($countadmin == 1) //Checks to see if you're an Administrator
{
$querymem = "SELECT * FROM Users"; //Gets all the records from the "User" table
$sqlmem = mysql_query($querymem);
echo "<select size='1' name='number'>";
while ($row = mysql_fetch_array($sqlmem))
{
$option = "<option value="{$row['number']}">{$row['number']}</option>"; //Should go through every record getting the "number"
echo $option;
}
echo "</select>";
}
I'm using the same code on another page but refering to the "Login" table and it works without a problem.
Try the above, I moved the echo $option to inside the while loop, and modified the $option var.
Of course, have you verified that $countadmin really does equal 1?
I tried that out but with no luck. But I noticed something I didn't really pick up on before. There are 4 options, which is the same amount of records that are in the table. So I think it's connecting, but not displaying the values. Also with "echo $option;" inside the while it shows 10 "options", so I moved it back out.
Also, I've logged in as a non-admin, and its setup do only display that users ID, which it does, so the $countadmin is working as expected.
from it too, and it loads the rown with no problems. But I can't get it to read the rows from the "Users" table. I even threw up a couple echo statements and it's not showing and name as being selected from the dropdown box, even though it shows the other information I put in.
Your second query is inside a conditional. If the conditional evaluates to false, the second query never runs. This certainly has nothing to do with connectivity. Check your conditonal to make sure it is evaluating to what you expect it to.
By default it would be true because the drop down is only within that conditional. So if it isn't true, it defaults to it showing just that user for the name. You know what I mean? I've tried it with a regular user and an admin, and it works.
Ok, so if I understand this correctly, your first query executes, but the second one does not. The second one is in a conditional that you said defaults to true, so the second query should always execute. Is this correct?