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'";
 ?>

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!

$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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.