Forum Moderators: coopster
It works just perfect, but the problem is I would like to be able to edit the diferents tables from here, and when I put an image with an link to one of the editpages, of course that image appears on all rows, I would like one image/link to appear in rows select 1, and another to appear in rows select 2 etc.
Any ideas?
if ($row = mysql_fetch_array($result)){
echo "<td><a href=".$links.">".$row["tipo"]."</a></TD>\n";
With this I guess you can see what I mean.
So now I have this selects that works perfect:
$result = mysql_query("(SELECT 1 as iden, bookings.id, etc FROM bookings)
UNION ALL
(SELECT 2 as iden2, limpiezas.id_limpieza, etc FROM limpiezas)
ORDER BY llegada, tipo;
", $dbh);
this uses foreach to display the result, code between /// is what I want to do, but of course doesn´t work:
echo "<table>\n";
while ($linea = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($linea as $valor_col) {
///if (isset($iden)){
if ($iden=="1"){
$link = "<a href=\"edit_reservas.php?\">Edit</a>";}
elseif ($iden=="2"){
$link = "<a href=\"edit_limpiezas.php?\">Edit</a>";}
}///
echo "\t\t<td>$valor_col</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
If I put this after the query the iden and iden2 are printed on top but of course I get an error on the table that is an fetch_array:
while ($row1 = mysql_fetch_object($result)) {
echo $row1->iden;
echo $row1->iden2;
}
mysql_free_result($result);
if ($row = mysql_fetch_array($result)){
echo "<table border = '1'> \n";
Any ideas
Only one problem, small I hope,
the id isn´t passed by in this:
$row->iden = "<a href=\"edit_limpiezas_diario.php?id_limpieza=".$row["id"]."\">Edit</a>";}
Could this been done with fetch_array?
or is that the diference between them.
Final code
?>
<Table>
<tr>
<td>Edit</td>
<td>Id</td>
</tr>
<?php
while ($row = mysql_fetch_object($result))
{
if ($row->iden=="1"){
$row->iden= "<a href=\"edit_reservas.php?\">Edit</a>";}
elseif ($row->iden=="2"){
$row->iden = "<a href=\"edit_limpiezas_diario.php?id_limpieza=".$row["id"]."\">Edit</a>";}
echo "<tr>
<td>$row->iden</td>
<td>$row->id</td>
<td>$row->llegada</td>
<td>$row->tipo</td>
<td>$link</TD>
</tr>";
}
?>
</table>
$row->iden = "<a href=\"edit_limpiezas_diario.php?id_limpieza=".$row->id."\">Edit</a>";
That assumes, of course, that the code a few lines later is working
<td>$row->id</td>
if that works, then you have 'id', but you must access it as an object member, not an array element.
An object is much more. It can include 'properties' that store data (similar to an array element) and 'methods' which are essentially functions that act on the object.
Confused? To get more confused, to a google search on "object oriented programming" ;-)
Tom
As well there are another thing I want to do, as having diferent backgrounds to rows depending on the queries result, I think that can be done using fetch_object,