I have a code in PHP like the next:
//$menutype is defined in this point, and no problem with it
$sql = "SELECT struct FROM menutype WHERE id=$menutype;";
$result = mysql_query($sql);
list($struct) = mysql_fetch_row($result);
$menu = explode("\n", $struct); //Explode to make an array with each line
foreach ($menu as $index => $value)
{
//$barid is defined in the top of the document and no issue with it
creatabla($barid, $value);
}
function creatabla($barid, $tipo)
{
$tipo = trim($tipo, ' '); //trim to delete unwanted spaces
$sql = "SELECT name FROM products WHERE tipo LIKE '%$tipo%' AND restaurante='$barid';";
$result = mysql_query($sql);
while(list($name) = mysql_fetch_row($result))
{
echo "$name";
}
}
Similar 'struct' row struct:
Line1
Line2
Line3
Line4AndLastLine
No car return after Last Line.
Well, the code usually works fine, but If I modify the 'Struct' row, some lines won't be read fine, so I usually need to edit the struct row in the advaced editor of the phpmyadmin.
What can I do to solve this issue? Can I try other kind of filter in the sql statement? What can I do to improve the trim or the explode function to solve this issue?
Thanks you to all in advance.
Structrow you say "some lines won't be read fine" - what does that mean? Do 2 lines come out looking as if they are on the same line? Or are some lines ignored altogether? It might be helpful to do aprint_r($menu);right after it is created.