stored procedure, convert string to integer

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sun Oct 07, 2012 10:21 pm

stored procedure, convert string to integer

Postby clement » Sun Oct 07, 2012 10:43 pm

Hi I am new to php.
I am trying to query by means of stored procedure.

Stored procedure "name_employee" is working.
I am not sure how to convert the variable "$sql" into number,


Code: Select all

   Ajax demo 2 using PHP and MySQL by Clement Yap
<script type="text/javascript">
function showUser(str)
   if (str=="")//If nothing, then do nothing.

   if (window.XMLHttpRequest)
     {// code for new browsers IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
     {// code for old browsers IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

      if (xmlhttp.readyState==4 && xmlhttp.status==200)


<select name="people" onchange="showUser(this.value)">
<option value="0">Select a person:</option>
<option value="1">Clement</option>
<option value="2">Ellen</option>
<option value="3">Joseph</option>
<option value="4">Louis</option>

<br />

<div id="txtHint"><b>Person info will be listed here.</b></div>



Code: Select all


$con = mysql_connect('localhost', 'root', '');
if (!$con)
  die('Could not connect: ' . mysql_error());

mysql_select_db("employee", $con);

//$sql="SELECT * FROM people WHERE id = '".$q."'";//by direct mysql syntax

$sql="call name_employee("intval($q)")";//by stored procedure

$result = mysql_query($sql);

echo "<table border='1'>

while($row = mysql_fetch_array($result))
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName']  . "</td>";
  echo "<td>" . $row['Age']       . "</td>";
  echo "<td>" . $row['Hometown']  . "</td>";
  echo "<td>" . $row['Job']       . "</td>";
  echo "</tr>";
echo "</table>";


Please advise

php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: stored procedure, convert string to integer

Postby seandisanti » Thu Oct 11, 2012 8:39 am

try changing

Code: Select all

$sql="call name_employee("intval($q)")";//by stored procedure


Code: Select all

$sql="call name_employee(".$q.")";//by stored procedure

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 2 guests