# MySQL & PHP

**URL:** <https://forum.kirupa.com/t/mysql-php/23499>\
**Category:** programming\
**Created:** [June 18, 2003, 6:07pm UTC](https://forum.kirupa.com/t/mysql-php/23499 "2003-06-18T18:07:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Voetsjoeba](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@Voetsjoeba](https://forum.kirupa.com/u/Voetsjoeba)\
**Post date:** [June 18, 2003, 6:07pm UTC](https://forum.kirupa.com/t/mysql-php/23499/1 "2003-06-18T18:07:42Z")

</div>

Hi everybody, me again 🙂

I got the MySQL tables to work at last. What I have now is a table called news, in which there are 4 fields and two rows of data. See the image below:

[EDIT] Image taken out due to server downtime[/EDIT]

So I have this script to put the data in a table.

```php

<?php
mysql_connect("hostname","username","password");
mysql_select_db("mydatabase");

$qr = mysql_query("SELECT * FROM news");

$nrows = mysql_num_rows($qr);
for ($i=0; $i < $nrows; $i++) {
  $row = mysql_fetch_array($qr);
}

?>
<html><head></head><body>
<table border="0" cellpadding="0" width="50%" cellspacing="0" height="124">
  <tr>
    <td width="100%" bgcolor="#FFFFCC" height="21"><? echo "<b>".$row['titel']."</b>&nbsp;&nbsp;&nbsp;".$row['datum'];?></td>
  </tr>
  <tr>
    <td width="100%" bgcolor="#FFFFFF" height="103"><? echo $row['inhoud']."<br>";?></td>
  </tr>
</table>
</body>
</html>

```

This works fine so far, see an example of one the created table [here](http://voetsjoeba.asianillusion.com/test2.php). The problem is, **how can I automatically add a table (in the PHP file, not in the database) when I add a new row of data to the database ?** I had one row first, and it worked fine, but when I added one, the script I have now shows the second one one instead of the first.

Can someone help me out please ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 18, 2003, 6:24pm UTC](https://forum.kirupa.com/t/mysql-php/23499/2 "2003-06-18T18:24:21Z")

</div>

This code should work:

```php

<html><head></head><body>
<table border="0" cellpadding="0" width="50%" cellspacing="0" height="124">

<?
mysql_connect("hostname","username","password");
mysql_select_db("mydatabase");

$qr = mysql_query("SELECT * FROM news");

$nrows = mysql_num_rows($qr);
for ($i=0; $i < $nrows; $i++) {
  $row = mysql_fetch_array($qr);
  print "<tr><td width=\"100%\" bgcolor=\"#FFFFCC\" height=\"21\"><b>" . $row['titel'] . "</b>&nbsp;&nbsp;&nbsp;" . $row['datum'] . "</td></tr>";
  print "<tr><td width=\"100%\" bgcolor=\"#FFFFFF\" height=\"103\">" . $row['inhoud'] . "</td></tr>";
}
?>
</table>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 18, 2003, 6:32pm UTC](https://forum.kirupa.com/t/mysql-php/23499/3 "2003-06-18T18:32:56Z")

</div>

Thanks Jubba 🙂 ! Works like a charm ! :thumb:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 3:12pm UTC](https://forum.kirupa.com/t/mysql-php/23499/4 "2003-06-20T15:12:19Z")

</div>

Hey Jubba, is it possible to get this auto-add feature into Flash (MX)? I know I might be asking a lot, but it would make my life so much better …

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 3:37pm UTC](https://forum.kirupa.com/t/mysql-php/23499/5 "2003-06-20T15:37:05Z")

</div>

yes but its not really a simple process… i have to go now, I’ll give you a hand later on. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 3:39pm UTC](https://forum.kirupa.com/t/mysql-php/23499/6 "2003-06-20T15:39:36Z")

</div>

Thanks m8 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 20, 2003, 9:40pm UTC](https://forum.kirupa.com/t/mysql-php/23499/7 "2003-06-20T21:40:34Z")

</div>

replace the 2 print lines by  
output="";

output.="&titel".$i."=".$row[‘titel’];  
output.="&content".$i."=".$row[‘inhoud’];

print $output;

(not tested…)

then in flash, use the titel1="…", titel2="…", content1="…",  
variables as you want…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 5:54am UTC](https://forum.kirupa.com/t/mysql-php/23499/8 "2003-06-21T05:54:44Z")

</div>

yeah what he said. Sorry I couldn’t get to this sooner. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 6:27am UTC](https://forum.kirupa.com/t/mysql-php/23499/9 "2003-06-21T06:27:16Z")

</div>

Don’t worry about it 🙂 Thanks guys 🙂
