Jump to content

Recommended Posts

Wondering if anyone can help. I am pretty new at this PHP stuff.

Here's the scenario....

Let's say you have a Flash website that has a section to display conference images. You have set up a 'conf1' table, 'conf2' table etc on your database but there are also other tables present that you don't need to access with different names.

 

Basically, in layman's terms I want to do this:

1. Search the database and find the 'conf' tables. (I did this already by using the 'substr' function that looks for the string 'conf' in the name of the table...not sure if there is an easier way? Below is what I attempted)

 

$numTestTables=0;

while ($row = mysql_fetch_row($result)) {

    if(substr($row[0],0,3)=="con"){

for($i=1;$i<=3;$i++){

$array[$i]=mysql_fetch_row($result);

$numTestTables=$numTestTables+1;

echo "<br />The value for the row at $i is $sql[$i].";

}

echo("<br />The number of conference tables is $numTestTables");

 

 

2. Once it finds the 'conf' tables, I have to name each image file uniquely so I can send those variables to Flash ('conf1img1='filename'', 'conf1img2='filename'', 'conf2img1='filename', 'conf2img2='filename'' etc)

I have done one successful search for the image names in ONE table when I just use the value for the total number of 'conf' tables ($numTestTables), but can't seem to make a loop work to get all 3 of them. I think it may be a loop within a loop or something? I can't find anything about getting a table name by name out there, just 'SELECT *' etc. Below is my hmmmm.....very amateur code:

 

$newString=$confNum.$numTestTables;

echo("<br />The last table with 'conf' in the name is $newString.");

 

$data = mysql_query("SELECT * FROM $newString")

or die(mysql_error());

Print "<br /><table border cellpadding=0>";

while($info = mysql_fetch_array($data))

{

Print "<tr>";

Print "<th>Small Image:</th> <td>".$info['imgSm'] . "</td> ";

Print "<th>Large Image:</th> <td>".$info['imgLg'] . " </td></tr>";

}

 

Print "</table>";

 

I think you have made things far more confusing than they need to be,

 

you might want to take a look at: http://www.tizag.com/mysqlTutorial/

 

it's a good set of tutorials that will get you through the basics of writing a query with PHP for mySQL

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.