I have to make a menu for a restaurant and I am kind of rookie at MySQL ..

The menu has to be 8 columns wide ( 1column + 7 days ) and 8 rows in height .

The problem is that it needs to be fully customisable , some cells having certain color and other stuff like that . So I can't use the table script i usually use .

I started this code , but got a problem . I don't know how to load a value from the database as variable in php .

I simplified the table so it's a lot easier to understand it .
Also , my database is currently set up like this :




$query =  mysql_query("SELECT * FROM DB_NAME");
$r1c1 = $value1_from_db; <!-- TEXT_r1c1 -->
$r1c2 = $value2_from_db; <!-- TEXT_r1c2 -->
$r8c8 = $value64_from_db;

<table width="900" border="1" cellspacing="0" cellpadding="0">
    <td><? echo $r1c1 ?></td> <!-- Row 1 , column 1 -->
    <td><? echo $r1c2 ?></td> <!-- Row 1 , column 2 -->
    <td><? echo $r1c3 ?></td> <!-- Row 1 , column 3 -->
    <td><? echo $r1c4 ?></td> <!-- Row 1 , column 4 -->
    <td><? echo $r1c5 ?></td> <!-- ................ -->
    <td><? echo $r1c6 ?></td>
    <td><? echo $r1c7 ?></td>
    <td><? echo $r1c8 ?></td>
    <td><? echo $r2c1 ?></td>
    <td><? echo $r2c2 ?></td>
    <td><? echo $r2c3 ?></td>
    <td><? echo $r2c4 ?></td>
    <td><? echo $r2c5 ?></td>
    <td><? echo $r2c6 ?></td>
    <td><? echo $r2c7 ?></td>
    <td><? echo $r2c8 ?></td>
    <td><? echo $r3c1 ?></td>
    <td><? echo $r3c2 ?></td>
    <td><? echo $r3c3 ?></td>
    <td><? echo $r3c4 ?></td>
    <td><? echo $r3c5 ?></td>
    <td><? echo $r3c6 ?></td>
    <td><? echo $r3c7 ?></td>
    <td><? echo $r3c8 ?></td>
 <!-- Here are 5 more rows of 8 columns each -->

Thanks in advance for any hint or guide .

First store the $query results to an array using mysql_fetch_array() .. and just need to use the table field name for getting the data like
$result for getting the TEXT_r8c8 like values ...
and just put that in a while loop
while ( the selected query result in an array )
// Rest display operation in table

Here I have added the sample code... for selecting the value and formatting table

$query=mysql_query("SELECT * FROM DB_NAME"));
echo "<table width=\"900\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
if ($tablecolumn==8)
echo "</tr>
echo "<td>".$r2c."</td>";
echo "</tr></table>";

Tried it and it doesn't work .
I get the following output

<table width="900" border="1" cellspacing="0" cellpadding="0">

R1C5 for example is the cell from Row : 1 , Column : 5
R4C2 for example is the cell from Row : 4 , Column : 2

Any idea ? anyone ?


Hi It means $r2c=$result; statment is not storing the value from table.
If yout table filed name is "TEXT" try to change that to use some other name like "table_TEXT" ...

After that run the code and make sure values are getting from table...

Then using "order by" clause for field POSITION in mysql query statement for getting the values in desired for output in table ...

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.