Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:07:21+00:00 2026-06-17T13:07:21+00:00

I have two MySQL tables in the same database, each with data. I have

  • 0
  1. I have two MySQL tables in the same database, each with data.
  2. I have a PHP results page that shows the data from the first MySQL table in a dynamic PHP table.
  3. One of the fields in the first MySQL table is a comma-separated list of IDs that relate to data in the second MySQL table.
  4. I have a second, nested/embedded dynamic PHP table within the first dynamic PHP table that pulls the data from the second MySQL table when the row ID appears in the comma-separated field of the first MySQL table. (i.e. one of the columns in the first dynamic PHP table contains the second, nested dynamic PHP table with data from the second MySQL table

See the PHP/HTML below:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_TravelSite, $TravelSite);
$query_Route = "SELECT * FROM SavedRoutes WHERE RouteCode = '".$_GET['rc']."'";
$Route = mysql_query($query_Route, $TravelSite) or die(mysql_error());
$row_Route = mysql_fetch_assoc($Route);
$totalRows_Route = mysql_num_rows($Route);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table border="0">
  <tr>
    <td>ID</td>
    <td>StartPoint</td>
    <td>StartPointLatLng</td>
    <td>EndPoint</td>
    <td>EndPointLatLng</td>
    <td>Waypoints</td>
    <td>Name</td>
    <td>Details</td>
    <td>RouteCode</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Route['ID']; ?></td>
      <td><?php echo $row_Route['StartPoint']; ?></td>
      <td><?php echo $row_Route['StartPointLatLng']; ?></td>
      <td><?php echo $row_Route['EndPoint']; ?></td>
      <td><?php echo $row_Route['EndPointLatLng']; ?></td>
      <td><p><?php echo $row_Route['Waypoints']; ?></p>
    <?PHP  $string = $row_Route['Waypoints'];
$slashstring = stripslashes($string);
$trimstring = rtrim($slashstring, "', '");
mysql_select_db($database_TravelSite, $TravelSite);
?>
        <p>echo $trimstring = <?PHP echo $trimstring; ?></p>
        <table border="0">
          <tr>
            <td>id</td>
            <td>Lng</td>
            <td>Lat</td>
            <td>Name</td>
          </tr>
          <?php
          mysql_select_db($database_TravelSite, $TravelSite);
$query_Markers = "SELECT * FROM markers WHERE ID IN('".$trimstring."')";
$Markers = mysql_query($query_Markers, $TravelSite) or die(mysql_error());
$row_Markers = mysql_fetch_assoc($Markers);
$totalRows_Markers = mysql_num_rows($Markers);
           do { ?>
            <tr>
              <td><?php echo $row_Markers['id']; ?></td>
              <td><?php echo $row_Markers['Lng']; ?></td>
              <td><?php echo $row_Markers['Lat']; ?></td>
              <td><p>
                <select multiple name="waypoints" id="waypoints">
                  <?php
do {  
?>
                  <option selected value="<?php echo $row_Markers['Lat'] . ", " . $row_Markers['Lng']?>"><?php echo $row_Markers['Lat'] . ", " . $row_Markers['Lng']?></option>
                  <?php
} while ($row_Markers = mysql_fetch_assoc($Markers));
  $rows = mysql_num_rows($Markers);
  if($rows > 0) {
      mysql_data_seek($Markers, 0);
      $row_Markers = mysql_fetch_assoc($Markers);
  }
?>
                </select>
              </p>
                <p><?php echo $row_Markers['Name']; ?></p></td>
            </tr>
            <?php } while ($row_Markers = mysql_fetch_assoc($Markers)); ?>
        </table>
<p>&nbsp;</p></td>
      <td><?php echo $row_Route['Name']; ?></td>
      <td><?php echo $row_Route['Details']; ?></td>
      <td><?php echo $row_Route['RouteCode']; ?></td>
    </tr>
    <?php } while ($row_Route = mysql_fetch_assoc($Route)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Markers);

mysql_free_result($Route);
?>

Now, when ever I run the page the following happens:

  • If there is only one item in the nested table (i.e. only one ID from
    the second table appears in the comma-separated field of the first
    table), then it renders perfectly.
  • However, if there is more than one (i.e. multiple IDs in the
    comma-separated field), then it renders the first item out to
    infinity (and crashes the browser).

What am I doing wrong? Clearly, nested tables is not the right way of doing what I am trying to do! n00b But what is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:07:22+00:00Added an answer on June 17, 2026 at 1:07 pm

    Remove the fav_food column from the first table, then add a 3rd table – fav_food:

    ID | fav_Food
    1  | 2
    1  | 4
    1  | 5
    1  | 12
    

    Then, use a JOIN to select all of John’s favorite foods, with details:

    SELECT *
    FROM `fav_food` JOIN `food`
    ON `food`.`ID`=`fav_food`.`fav_food`
    WHERE `fav_food`.`ID`=1
    

    (use a different query to select John’s details)

    In general, as you said, nested tables is not the best idea when you can use a regular table with JOIN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two same tables.Database mysql. How can I compare two tables? Table1,Table2
I have two mysql tables and i want to merge the results of these
I was thinking that I would have two tables for mysql. One for storing
I have a MySQL database with a lot of tables, and I have two
Consider these two tables stored in a MySQL database. The first stores a list
I have two servers which contains a same database, same tables structure with different
Is there a PHP code that let's you compare 2 MySQL tables with each
I have two database tables, one in MYSQL and one in MSSQL. Both have
I have two mySQL tables in my database Training: +-------------+------------+------------+------------+-...-+------------+ | Training_ID | 09-06-2012
I have two tables in MySQL sales database: Orders table: CREATE TABLE salestest.`orders` (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.