Jump to content

quiry from dropdown list problem


nicedad

Recommended Posts

Hello everyone,
I'm a newbie in PHP thus have an issue running the following code. it always says

(Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\showDetails1.php on line 5) or see attached image.

in this code I try to inquiry data from a table using a dropdow list.

 

Is there anyone of help? any help will be appreciated.

<?php
$link = mysqli_connect("localhost","root","", "home_work");
//mysql_select_db("home_work",$link);
$sql = "SELECT * FROM dropdown ";
$aResult = mysql_query($sql);
if($_REQUEST['frm_action'] == 3)
{
if ($_REQUEST['cust_id'] == 0)
{
$id = $_REQUEST['cust_id'];
$sqlCustomer = "SELECT * FROM dropdown ";
}
else
{
$id = $_REQUEST['cust_id'];
$sqlCustomer = "SELECT * FROM dropdown WHERE id ='$id'";
}
$aCustomer = mysql_query($sqlCustomer);
}
?>
<html>
<head>
<script type="text/javascript">
function changeSID()
{
oForm       = eval(document.getElementById("frmForm"));
iCustomerId = document.getElementById("sid").value;
url         = "showDetails1.php?frm_action=3&cust_id=" +iCustomerId;
document.location = url;
}
</script>
</head>

<body>
<form name="frmForm" id="frmForm" >
<table border="0" cellspacing="2" cellpadding="2" width="40%">
<tr>
<td align="right" ><strong>Sid</strong></td>
<td align="left"><select name="sid" id="sid" onchange="javascript:changeSID();">
<option value="">Select</option>
<option value="0">All</option> 

<?php
$sid1 = $_REQUEST['cust_id'];

while($rows=mysql_fetch_array($aResult,MYSQL_ASSOC))
{
$id  = $rows['id'];
$sid = $rows['sid'];
if($sid1 == $id)
{
$chkselect = 'selected';

}
else
{
$chkselect ='';
}
?>
<option value="<?php echo  $id;?>"<?php echo $chkselect;?>><?php echo $sid;?></option>
<?php } ?>
</td>
</tr>
<?php if($_REQUEST['frm_action'] == 3) { ?>
<tr>
<td colspan="2">
<table  style="border:1px solid #003366;" cellspacing="2" cellpadding="2" width="100%" bgcolor="#003366">
<tr bgcolor="#EFEFEF">
<td><b><font color='Red'>Sid</font></b></td>
<td><b><font color='Red'>Sname</font></b></td>
<td><b><font color='Red'>Age</font></b></td>
</tr>
<?php
while($row1 = @mysql_fetch_array($aCustomer,MYSQL_ASSOC))
{
$sid   = $row1['sid'];
$sname = $row1['sname'];
$age   = $row1['age'];
?>
<tr bgcolor="#FFFFFF">
<td><b><font color='#663300'><?php echo $sid;?></font></b></td>
<td><b><font color='#663300'><?php echo $sname;?></font></b></td>
<td><b><font color='#663300'><?php echo $age;?></font></b></td>
</tr>
<?php } ?>
</table>
</td>
</tr>
<?php } ?>
</table>
</form>
</body>
</html>

post-179690-0-44236100-1441793449_thumb.png

Link to comment
Share on other sites

Hi QuickOldCar,

thanks a lot for your help. I tried to fix the problem as you adviced. Unfortunately, occured another one regarding mysql_fetch_array ( ) function

(Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\showDetails1.php on line 46).

here is the improve code:

<?php
$link = mysqli_connect("localhost","root","", "home_work");
//mysql_select_db("home_work",$link);
$sql = "SELECT * FROM dropdown ";
$aResult = mysqli_query($link, $sql);
if($_REQUEST['frm_action'] == 3)
{
if ($_REQUEST['cust_id'] == 0)
{
$id = $_REQUEST['cust_id'];
$sqlCustomer = "SELECT * FROM dropdown ";
}
else
{
$id = $_REQUEST['cust_id'];
$sqlCustomer = "SELECT * FROM dropdown WHERE id ='$id'";
}
$aCustomer = mysqli_query($link, $sqlCustomer);
}
?>
<html>
<head>
<script type="text/javascript">
function changeSID()
{
oForm       = eval(document.getElementById("frmForm"));
iCustomerId = document.getElementById("sid").value;
url         = "showDetails1.php?frm_action=3&cust_id=" +iCustomerId;
document.location = url;
}
</script>
</head>

<body>
<form name="frmForm" id="frmForm" >
<table border="0" cellspacing="2" cellpadding="2" width="40%">
<tr>
<td align="right" ><strong>Sid</strong></td>
<td align="left"><select name="sid" id="sid" onchange="javascript:changeSID();">
<option value="">Select</option>
<option value="0">All</option> 

<?php
$sid1 = $_REQUEST['cust_id'];

while($rows=mysql_fetch_array($sqlCustomer, MYSQL_ASSOC))
{
$id  = $rows['id'];
$sid = $rows['sid'];
if($sid1 == $id)
{
$chkselect = 'selected';

}
else
{
$chkselect ='';
}
?>
<option value="<?php echo  $id;?>"<?php echo $chkselect;?>><?php echo $sid;?></option>
<?php } ?>
</td>
</tr>
<?php if($_REQUEST['frm_action'] == 3) { ?>
<tr>
<td colspan="2">
<table  style="border:1px solid #003366;" cellspacing="2" cellpadding="2" width="100%" bgcolor="#003366">
<tr bgcolor="#EFEFEF">
<td><b><font color='Red'>Sid</font></b></td>
<td><b><font color='Red'>Sname</font></b></td>
<td><b><font color='Red'>Age</font></b></td>
</tr>
<?php
while($row1 = @mysql_fetch_array($aCustomer,MYSQL_ASSOC))
{
$sid   = $row1['sid'];
$sname = $row1['sname'];
$age   = $row1['age'];
?>
<tr bgcolor="#FFFFFF">
<td><b><font color='#663300'><?php echo $sid;?></font></b></td>
<td><b><font color='#663300'><?php echo $sname;?></font></b></td>
<td><b><font color='#663300'><?php echo $age;?></font></b></td>
</tr>
<?php } ?>
</table>
</td>
</tr>
<?php } ?>
</table>
</form>
</body>
</html>

cheers,

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.