Hi I got a database where one of the feilds are bool giving a result of 0 or 1. Whats the easiest way of turning this into a yes or no? I tried this but it dont seem to work though. <?php //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost", "johnmev_user1", "Pass1"); //select which database you want to edit mysql_select_db("cp"); //If cmd has not been initialized if(!isset($cmd)) { //display all the cars $result = mysql_query("select * from data order by id"); //run the while loop that grabs all the cars while($r=mysql_fetch_array($result)) { //grab the make, model,special and the ID $make=$r['make'];//take out the make $model=$r['model'];//take out the model $special=$r['special']; //take out the special $id=$r['id'];//take out the id //Translate special bool into yes no if ( $special == "1" ) { $spec=yes; } else { $spec=no; { //show the make and model a link in a list echo "<li>"; echo "<a href='edit.php?cmd=edit&id=$id'>Edit - $make $model</a> - $spec"; echo "</li>"; } } ?> PHP:
I think you are missing an ending bracket after: $spec=no; If there's more to it than that include the error message you are getting or whatever information you have that leads you to believe its not working.
Well, first you need to change while($r=mysql_fetch_array($result)) PHP: To while($r=mysql_fetch_assoc($result)) PHP: Notice the difference in fetching the array and the assoc. The array, still works - but you $vars will be called like so. $var[0] $var[1] $var[2] etc. In this instance you're calling the associated name for it. So, it would be mysql_fetch_assoc (I.E. $var['special']) Also, characters need to be encapsed by quotations in variables. I.E. $var = yes; Needs to be $var = 'yes'; Thanks, hope this guides you in the right direction.
Lol asif I put an open bracket instead of close, cheers. Think I need a break now am tired and making dumb mistakes. cheers agen mate.