0

i am trying to use the explode function to take a variable as the string under consideratiom but its not working. can some one help me on this one please??
thanks

<?php

$hostname = "localhost";
$username = "root";
$password = "hayden";
$database = "ecng3020";


$con = mysql_connect("$hostname","$username","$password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("$database", $con);
  
 $sql= "SELECT  parameters FROM rules WHERE id='1'";
 //$result=mysql_query($sql);
 if ($result=mysql_query($sql))
	echo '<p>nice</p>';
	else
	echo 'good shit';
 


 
 $row = mysql_fetch_row($result);
 //echo"$row[0]";
// $par= $row[0];  // this will contain the string containing the parameters
  
  
  
$par= explode (",",$row);
 echo " $par[2]";

 //$sql_1=" SELECT * course_status FROM student_course WHERE course_code ='$par'";
 ?>

Edited by nav33n: Please use [code] tag to wrap your code for easy readability.

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by nav33n
0

Two things:
1) use code tags
2) you are missing all of the braces in this section:

if ($result=mysql_query($sql)) //problem starts here
echo '<p>nice</p>';
else
echo 'good shit';




$row = mysql_fetch_row($result);
//echo"$row[0]";
// $par= $row[0]; // this will contain the string containing the parameters



$par= explode (",",$row);
echo " $par[2]";

//$sql_1=" SELECT * course_status FROM student_course WHERE course_code ='$par'";
?>

You might also try mysql_fetch_array()
Ps: you might want to change your database, user, ans PW now that you have shown them to the world!

0

$row will have an array. You can explode only strings, not arrays. And, as JRM mentioned, I don't recommend the use of mysql_fetch_row. Since this returns an numeric index array, you will have to use $row[0], $row[1] etc.
Say, after sometime, you change the database structure, by adding/removing a field [first field for example], then that is going to be a big problem as $row[1] will now correspond to the newly added field!

Always use mysql_fetch_array or mysql_fetch_assoc.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.