Jump to content

[SOLVED] script problem


mishuk

Recommended Posts

Hi

I am working on a piece of code that basis the rows returned from a select query on the username of a session.

I have got this far and it works for all users who do not have a usergrp of 1 however people with a usergrp of one do not get any results back from the query.  I think my problem lies with the if statement that checks if the value of $res == 1 but i am stuck for ideas

 

<?php $user = ($_SESSION['username']);
    $usercheck = mysql_query("SELECT usergrp FROM tbl_authuser WHERE username = '$user'");
    $result = mysql_fetch_array($usercheck);
    $res = $result['usergrp'];

    $usercheck = mysql_query("SELECT auth_id FROM tbl_authuser WHERE username = '$user'");
    $result = mysql_fetch_array($usercheck);
    $sch = $result['auth_id'];

    if ($res == 1) {
$final = mysql_query("select schoolname from tbl_school Order by schoolname");
	}
$final = mysql_query("select schoolname from tbl_school where auth_id = '$sch' Order by schoolname");

echo'<select name="school">';
     	    if(mysql_num_rows($final)==0)
	echo "No Data";
    else
	echo"<option>Select:</option>";
	for($i=0;$i<mysql_num_rows($final);$i++)
		{
		$row=mysql_fetch_assoc($final);
		echo"<option>$row[schoolname]</option>";
		}
	echo'</select>';
?>

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/38017-solved-script-problem/
Share on other sites

I'm not very good with scripting yet. I'm still learning but maybe use a Switch statement instead of If?

 

switch ($res) {

    case "1":

// do something

        break;

    case "2":

  // do something else     

        break;

 

}

 

I think that's right. just tryin' to help. :)

 

Link to comment
https://forums.phpfreaks.com/topic/38017-solved-script-problem/#findComment-181969
Share on other sites

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.