Php mysql incluye una identificación de fila en otra fila

I have a mysql database where i'd like to include the contents of a row in another row. The content of all my rows is static html. I am looking for something similar to the 'include' command.

Esto es un ejemplo:

Row 1=A
Row 2=fast
Row 3=red

In Row 4 i have the content 'car'. I need to include the content of row 1, 2, and 3 before the content of row 4. Therefore the output would be A fast red car.

Is this possible? I only have one database, so there are not external references.

My mysql knowledge is near zero. My programmer was lazy and copied all the same html to each row. So now when i update i have to update the static html in many rows.

Muchas Gracias

preguntado el 29 de julio de 12 a las 00:07

Why on earth do you have HTML in your database? -

Oh no! You shouldn't write your app the way you do. Why do you store html in sql? Lol -

@metal_fan can you enlighten me a bit why not store html in a database? -

@Kyokasuigetsu Actually - You can always store/generate html in database - but this is worst practice I ever faced because 1) You always need establish the link (what if connection fall because of server overload?!) 2) You need to select database => you need generate query => you need to check for some conditions (as usual) etc etc... This is just dirty and anti MVC pattern. This will make your code just illegible for follow debug /maintain. Really. Take a look at popular product written in PHP - they use logic(classes, functions) separately from it's view. View is bunch of HTML files (usual) -

mmm, i need a new programmer then Thanks for the advice. -

1 Respuestas

Simplemente podría hacer algo como esto:

$query = mysqli_query($database_connection, "SELECT * FROM table_name LIMIT 4");
while ($row = mysqli_fetch_array($query)) {

echo $row['column_name']; }

Espero que esto sea lo que quieres decir.

Respondido 29 Jul 12, 00:07

I forgot: change the first line to this: $query = mysqli_query($database_connection, "SELECT * FROM table_name LIMIT 4 ORDER BY column_name ASC"); which will get you row 1 first, then row 2 etc... - DannyCruzeira

Ok, sorry for my ignorance, but have no idea how i can modify your code to include row ids? - user1560275

How does the structure of your table look like? How many columns are there? - DannyCruzeira

I have 6 columns and around 300 rows. My order cannot be ASC as some of the IDs are not in order. - user1560275

My insert command would be something like this: <insert id 4, 6, 13> NEW TEXT - user1560275

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.