By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Array Formating and Display Error

100+
P: 384
I have this function below and it takes in the id of the article and the table its from in the database.
The first query will return a string like so ;1|;4|;7|;8| which is assigned to $format_array, what im trying to do in the second query and loop is to check the id returned from each row of review_format table and if its equal to one of the numbers in the $format_array that it will echo out to screen "checked".
Expand|Select|Wrap|Line Numbers
  1. function display_edit_format($id,$table) {
  2.  
  3.     $sql = mysql_query("SELECT format FROM ".$table." WHERE id=".$id."");
  4.     while ($row = mysql_fetch_array($sql))
  5.     {
  6.         $i = 0;
  7.         $format_array = $row['format'];
  8.         $array_size = sizeof($format_array);
  9.  
  10.         $sql = mysql_query("SELECT id,description FROM review_formats");
  11.         while ($row = mysql_fetch_array($sql))
  12.         {
  13.             echo'<input type="checkbox" name="format[]" value=";'.$row['id'].'|" class="form"';
  14.                 for($i = 0;$i < $array_size;$i++)
  15.                 {
  16.                     if($row['id'] == $format_array[$i])
  17.                     {
  18.                         echo' checked';
  19.                     }
  20.                 }
  21.             echo'>'.$row['description'].'<br>';
  22.         }
  23.     }
  24. }
Sep 28 '08 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi.

If your first query is returning all those ID's as a single string (which is a bad idea btw. See this article to see more), then you will have to split them up before you can loop through them as an array.

Check out the explode function to do that.
Sep 29 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.