Jump to content

Recommended Posts

hey guys

 

Doing last bit of site now and after doing full testing I found 1 little bug that I don't like :)

I created an appointment section with a table to display resuilts from mysql, works great, but add more than 1 appiontment and its almost adding a whole new page

See attachment for pic

Heres the code for the table

<?php  echo '<h2>Customer Appointments</h2>'; ?>
</span></div><table width="1248" border="3" align="center">
  <tr class="new">
           <td width="116" class="re" style="text-align: center"><strong>Date Booked</strong></td>
           <td width="96" class="re" style="text-align: center"><strong class="table">Time Booked</strong></td>
           <td width="823" class="re" style="text-align: center"><strong class="table">Notes</strong></td>
  </tr>
         <?php do { ?>
           <tr class="table">
             <td class="re" style="text-align: center; color: #FFF;"><?php echo $row['datebooked']; ?></td>
             <td class="re" style="text-align: center"><?php echo $row['timebooked']; ?></td>
             <td class="re" style="text-align: center"><?php echo $row['notes']; ?></td>
  </tr>
           <?php } while ($row = mysql_fetch_assoc($Recordset1)); ?>
</table>
          <span class="re">
          <?php

Is there anyway I can make the Titles: Date Booked, Time Booked, Notes and have all results showing directly underneath?

post-172571-0-69888600-1409830857_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/290847-table-with-repeat-region/
Share on other sites

 

 

Is there anyway I can make the Titles: Date Booked, Time Booked, Notes and have all results showing directly underneath?

The code you posted should be doing just that.

 

However from  the screenshot you posted it appears the code you have posted is within another while loop (or in your wording a repeat region) which is why the headings are being duplicated.

Here is the entire page code:

<?php require_once('/Connections/new.php'); ?>
<?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;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_new, $new);
$query_Recordset1 = sprintf("SELECT * FROM appointments WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $new) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
 session_START() ?>
<?PHP 




// get the files belonging to the logged in user
$result = mysql_query('SELECT id, username, datebooked, timebooked, notes FROM appointments WHERE username=\''.mysql_real_escape_string($_SESSION['MM_Username']).'\'');

// check query did execute without errors
if($result)
{
	
    // output each file
    while($row = mysql_fetch_assoc($result))
    {
    	?>
<title>Appointments</title>

    	<style type="text/css">
    	body p {
	text-align: center;
}
        body {
	background-image: url(slate.jpg);
}
        .new {
	color: #FFF;
}
        .new {
	font-weight: bold;
}
        .new .new {
	text-align: left;
}
        .new {
	color: #FFF;
}
        .re {
	text-align: center;
}
        .table .re {
	color: #FFF;
}
        .table .re {
	color: #FFF;
}
        </style>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" align="center"/>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

</p>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" align="center"/>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

</p>
<ul id="MenuBar1" class="MenuBarHorizontal">
  <li><a class="MenuBarItemSubmenu" href="success.php">Home</a>
  <li><a href="#">Gallery</a></li>
  <li><a class="MenuBarItemSubmenu" href="appointments.php">Visits</a>
  <li><a class="MenuBarItemSubmenu" href="#">Contact</a>
</ul>
<p align="center"><br>
  <br>
</p>
<p align="center"><img src="/images.jpg" width="323" height="156"><br />
<p align="center">  </p>
<div align="center">
  <span class="new">
  <?php  echo '<h2>Customer Appointments</h2>'; ?>
</span></div><table width="1248" border="3" align="center">
  <tr class="new">
           <td width="116" class="re" style="text-align: center"><strong>Date Booked</strong></td>
           <td width="96" class="re" style="text-align: center"><strong class="table">Time Booked</strong></td>
           <td width="823" class="re" style="text-align: center"><strong class="table">Notes</strong></td>
  </tr>
         <?php do { ?>
           <tr class="table">
             <td class="re" style="text-align: center; color: #FFF;"><?php echo $row['datebooked']; ?></td>
             <td class="re" style="text-align: center"><?php echo $row['timebooked']; ?></td>
             <td class="re" style="text-align: center"><?php echo $row['notes']; ?></td>
  </tr>
           <?php } while ($row = mysql_fetch_assoc($Recordset1)); ?>
</table>
          <span class="re">
          <?php
    }
// query did not execute, log or show error message
} else {
    trigger_error('Cannot get users files from database: ' . mysql_error());
}

mysql_free_result($Recordset1);
?>
          </span>

This code should be immediately restructure from scratch ;) You don't have to repeat your css and javascrip code adding them into while loops. Why are you using two identical queries: 

SELECT * FROM appointments WHERE username = %s"

//and 


SELECT id, username, datebooked, timebooked, notes FROM appointments WHERE username=

Hmm, Css and javasript was added by dreamweaver to add the menubar I think  ::)

 

and I'm not sure why 2 queries are in there, I'll look at that l8r as its time to pick kids up from school

Don't say to rebuild it lol, its nearly 99% working apart from this  :tease-01:

I am at work now to get my time looking more deeply into this beautiful script, but you should die here thought :)

$query_Recordset1 = sprintf("SELECT * FROM appointments WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $new) or die(mysql_error());

What is $new? your database credentials?

Edited by jazzman1

I removed a large section of code and refreshed and its looking a little more proper, but have a few errors :D

 

New code

<?php require_once('/Connections/new.php'); ?>
<?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;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_new, $new);
$query_Recordset1 = sprintf("SELECT * FROM appointments WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $new) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
 session_START() ?>
<?PHP 




// get the files belonging to the logged in user
$result = mysql_query('SELECT id, username, datebooked, timebooked, notes FROM appointments WHERE username=\''.mysql_real_escape_string($_SESSION['MM_Username']).'\'');

// check query did execute without errors
if($result)
{
	
    // output each file
    while($row = mysql_fetch_assoc($result))
    {
    	?>
<title>Appointments</title>

    	<style type="text/css">
    	body p {
	text-align: center;
}
        body {
	background-image: url(slate.jpg);
}
        .new {
	color: #FFF;
}
        .new {
	font-weight: bold;
}
        .new .new {
	text-align: left;
}
        .new {
	color: #FFF;
}
        .re {
	text-align: center;
}
        .table .re {
	color: #FFF;
}
        .table .re {
	color: #FFF;
}
        </style>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" align="center"/>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

</p>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" align="center"/>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

</p>
<ul id="MenuBar1" class="MenuBarHorizontal">
  <li><a class="MenuBarItemSubmenu" href="success.php">Home</a>
  <li><a href="#">Gallery</a></li>
  <li><a class="MenuBarItemSubmenu" href="appointments.php">Visits</a>
  <li><a class="MenuBarItemSubmenu" href="#">Contact</a>
</ul>
<p align="center"><br>
  <br>
</p>
<p align="center"><img src="/images.jpg" width="323" height="156"><br />
<p align="center">  </p>
<div align="center">
  <span class="new">
  <?php  echo '<h2>Customer Appointments</h2>'; ?>
</span></div><table width="1248" border="3" align="center">
  <tr class="new">
           <td width="116" class="re" style="text-align: center"><strong>Date Booked</strong></td>
           <td width="96" class="re" style="text-align: center"><strong class="table">Time Booked</strong></td>
           <td width="823" class="re" style="text-align: center"><strong class="table">Notes</strong></td>
  </tr>
         <?php do { ?>
           <tr class="table">
             <td class="re" style="text-align: center; color: #FFF;"><?php echo $row['datebooked']; ?></td>
             <td class="re" style="text-align: center"><?php echo $row['timebooked']; ?></td>
             <td class="re" style="text-align: center"><?php echo $row['notes']; ?></td>
  </tr>
           <?php } while ($row = mysql_fetch_assoc($Recordset1)); ?>
</table>
          <span class="re">
          <?php
    }
// query did not execute, log or show error message
} else {
    trigger_error('Cannot get users files from database: ' . mysql_error());
}

mysql_free_result($Recordset1);
?>
          </span>

Now I can see the table is bigger but i have these

 

Notice: Undefined variable: row in blah on line 106 - 107 - 108

 

yeah $new is the connection to the db 

<?php require_once('/Connections/new.php'); ?> 

Try,

<?php

ini_set('display_startup_errors', 1);

ini_set('display_errors', 1);

error_reporting(-1);
?>

<?php session_start(true); ?>

<?php require_once('/Connections/new.php'); ?>

<?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;
  }
  }


  $colname_Recordset1 = "-1";

  if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = $_SESSION['MM_Username'];
  }

  mysql_select_db($database_new, $new);
  $query_Recordset1 = sprintf("SELECT * FROM appointments WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
  $Recordset1 = mysql_query($query_Recordset1, $new) or die(mysql_error());
  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($Recordset1);

 */
?>

<title>Appointments</title>

<style type="text/css">
    body p {
        text-align: center;
    }
    body {
        background-image: url(slate.jpg);
    }
    .new {
        color: #FFF;
    }
    .new {
        font-weight: bold;
    }
    .new .new {
        text-align: left;
    }
    .new {
        color: #FFF;
    }
    .re {
        text-align: center;
    }
    .table .re {
        color: #FFF;
    }
    .table .re {
        color: #FFF;
    }
</style>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" align="center"/>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

</p>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" align="center"/>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

</p>
<ul id="MenuBar1" class="MenuBarHorizontal">
    <li><a class="MenuBarItemSubmenu" href="success.php">Home</a>
    <li><a href="#">Gallery</a></li>
    <li><a class="MenuBarItemSubmenu" href="appointments.php">Visits</a>
    <li><a class="MenuBarItemSubmenu" href="#">Contact</a>
</ul>
<p align="center"><br>
    <br>
</p>
<p align="center"><img src="/images.jpg" width="323" height="156"><br />
<p align="center">  </p>
<div align="center">
    <span class="new">
<?php echo '<h2>Customer Appointments</h2>'; ?>
    </span></div><table width="1248" border="3" align="center">
    <tr class="new">
        <td width="116" class="re" style="text-align: center"><strong>Date Booked</strong></td>
        <td width="96" class="re" style="text-align: center"><strong class="table">Time Booked</strong></td>
        <td width="823" class="re" style="text-align: center"><strong class="table">Notes</strong></td>
    </tr>

<?php

$sql = sprintf("SELECT datebooked, timebooked, notes FROM appointments WHERE username='%s'", mysql_real_escape_string($_SESSION['MM_Username']));

$result = mysql_query($sql);

// check query did execute without errors
if ($result) {

    // output each file
    while ($row = mysql_fetch_assoc($result)): ?>

            <tr class="table">
                <td class="re" style="text-align: center; color: #FFF;"><?php echo $row['datebooked']; ?></td>
                <td class="re" style="text-align: center"><?php echo $row['timebooked']; ?></td>
                <td class="re" style="text-align: center"><?php echo $row['notes']; ?></td>
            </tr>

        </table>
        <span class="re">
    <?php
    endwhile; // end the while loop

// query did not execute, log or show error message
} else {
    trigger_error('Cannot get users files from database: ' . mysql_error());
}

mysql_free_result($result);
?>
</span>

Let me know if you get an error.

Edited by jazzman1

Would this be easy to use for gallery with adding mm_username as I have added username to the table :)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?php
mysql_connect ("localhost","root","1234");
mysql_select_db ("company");
$res=mysql_query ("select * from pictures");
echo "<table>";
while ($row=mysql_fetch_array($res))
{
echo "<tr>";
echo "<td>";?> <img src="<?php echo $row["images1"]; ?> height "100" width "100"> <?php echo "</td>";
echo "<td>"; echo $row["name"]; echo "</td>";

echo "</td>";



echo "</tr>";
	
	
	
}
echo "</table>"
?>
</body>
</html>

 Yeap, you got it. This is a pretty simple structure without any security, styling, javascript, etc.. but it would work. Get the image data (path,size,type, etc...) from a db table and display the image using an image tag. That's all you have to do. Try. It wouldn't hurt you :)

Edited by jazzman1

I got it working without using  MM_Username, but since adding it in, I get Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\ridge\image2.php on line 38

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php session_START() ?>
<?php
mysql_connect ("localhost","username","password");
mysql_select_db ("company");

if (isset($_SESSION['MM_Username'])) {
  $row_username = $_SESSION['MM_Username'];
$res=mysql_query ("select * from pictures");
echo "<table>";
while ($row=mysql_fetch_array($res))

{
?>	
echo "<tr>";
echo "<td>"; <img src="<?php echo $row["images1"]; ?>" height "100" width "100"> <?php echo "</td>";
echo "<td>"; echo $row["name"]; echo "</td>";

echo "</td>";



echo "</tr>";
	
	
	
}
echo "</table>"
?>
</body>
</html>
while ($row=mysql_fetch_array($res))
{
?>    //You are terminating php here, but using php on next line
echo "<tr>";

So the very last ?> in the file doesn't have a matching open php tag...just 2 php close tags.

Edited by CroNiX
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.