Jump to content

Recommended Posts

How can you display more than one result in a text area? The way i have my code now displays just the first result in the text area.

<?
include "config.php";
$db = mysql_connect($host,$login,$password);
mysql_select_db($base,$db);


if (!verifyuser() )

   { header( "Location: login.php" ); }

else {

?>
<head>
<title>Diary</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF" topmargin="5" leftmargin="5" marginheight="5" marginwidth="5" ><center>
<?
if  (isset($_POST["event_desc"])) { $event_desc = $_POST['event_desc']; }
if  (isset($_POST["submit"]) && (!isset($_POST["event_desc"]) or empty($event_desc) ))
{ ?>
<script language="Javascript" type="text/javascript">
<!--
        window.open('empty.html', '_myevent', 'HEIGHT=100,resizable=yes,WIDTH=400');

//-->
</script>
<?
}
if ( isset($_POST["submit"]) && !empty($event_desc)) {
   $eventyear = $_POST['eventyear'];
   $eventmonth = $_POST['eventmonth'];
   $eventdate = $_POST['eventdate'];
   $id = $_POST['id'];
   $day_in_a_mth = date('t', mktime(0, 0, 0, $eventmonth, 1, $eventyear)) ;

if ($day_in_a_mth >= $eventdate )
  {
   $fulldate = $eventyear."-".$eventmonth."-".$eventdate;
   $event_desc = $_POST['event_desc'];
   $id = $_POST['id'];
  $sql = "INSERT INTO event SET date='$fulldate', event_desc='$event_desc', id='$id'";
  $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
  message( "ADD EVENT", "DATA ENTERED");  }
else {
  message( "ERROR", "DATE ENTERED NOT VALID");

  }
}
else {

$query = "SELECT * FROM propertys WHERE price BETWEEN '".$_GET['minprice']."' AND '".$_GET['maxprice']."'ORDER BY price DESC";
$result = mysql_query($query); 
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$address=mysql_result($result,$i,"address");
$price=mysql_result($result,$i,"price");
$ref=mysql_result($result,$i,"ref");		
?>
<?
++$i;
}
}
?>

<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" name="post">
<table width="90%" class="tdborder" cellSpacing=1 cellPadding=6  border=0>
<tr>
   <td class="header" bgcolor="#6699ff"><center>Appointments</center></td></tr>
<tr>
   <td>
      <table width="100%" class=tableborder cellSpacing=1 cellPadding=0  border=0>
       <tr>
         <td><div class="genfont"><b>Date</b></div>
        		<div><select name="eventyear">
                  ....                 </select>
                  <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
         </td>
       </tr>
     </table>
   </td>
  <tr>
   <td><div class="genfont">Enter event :</div>
       <textarea name="event_desc" rows="4" cols="15" wrap="virtual" style="width:550px; font-size:12px" tabindex="3">
R<? print "$price"?> #<? print "$ref"?> <? print "$address"?> </textarea>
   </td>
  </tr>
  <tr>
    <td><div align="center">
      <input type="submit" value="Submit" name="submit" />
      <?
}	

?>
    </form>


Link to comment
https://forums.phpfreaks.com/topic/71359-solved-displaying-in-text-areas/
Share on other sites

not tested but this should do the trick the issue u had before is that you were looping through all your data and then echoing a variable back but as it was a variable it only holds the last value you set it too.

 

<?
include "config.php";
$db = mysql_connect($host,$login,$password);
mysql_select_db($base,$db);


if (!verifyuser() )

   { header( "Location: login.php" ); }

else {

?>
<head>
<title>Diary</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF" topmargin="5" leftmargin="5" marginheight="5" marginwidth="5" ><center>
<?
if  (isset($_POST["event_desc"])) { $event_desc = $_POST['event_desc']; }
if  (isset($_POST["submit"]) && (!isset($_POST["event_desc"]) or empty($event_desc) ))
{ ?>
<script language="Javascript" type="text/javascript">
<!--
        window.open('empty.html', '_myevent', 'HEIGHT=100,resizable=yes,WIDTH=400');

//-->
</script>
<?
}
if ( isset($_POST["submit"]) && !empty($event_desc)) {
   $eventyear = $_POST['eventyear'];
   $eventmonth = $_POST['eventmonth'];
   $eventdate = $_POST['eventdate'];
   $id = $_POST['id'];
   $day_in_a_mth = date('t', mktime(0, 0, 0, $eventmonth, 1, $eventyear)) ;

if ($day_in_a_mth >= $eventdate )
  {
   $fulldate = $eventyear."-".$eventmonth."-".$eventdate;
   $event_desc = $_POST['event_desc'];
   $id = $_POST['id'];
  $sql = "INSERT INTO event SET date='$fulldate', event_desc='$event_desc', id='$id'";
  $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
  message( "ADD EVENT", "DATA ENTERED");  }
else {
  message( "ERROR", "DATE ENTERED NOT VALID");

  }
}
else {
?>

<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" name="post">
<table width="90%" class="tdborder" cellSpacing=1 cellPadding=6  border=0>
<tr>
   <td class="header" bgcolor="#6699ff"><center>Appointments</center></td></tr>
<tr>
   <td>
      <table width="100%" class=tableborder cellSpacing=1 cellPadding=0  border=0>
       <tr>
         <td><div class="genfont"><b>Date</b></div>
        		<div><select name="eventyear">
                  ....                 </select>
                  <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
         </td>
       </tr>
     </table>
   </td>
  <tr>
   <td><div class="genfont">Enter event :</div>
       <textarea name="event_desc" rows="4" cols="15" wrap="virtual" style="width:550px; font-size:12px" tabindex="3">
<?php
$query = "SELECT * FROM propertys WHERE price BETWEEN '".$_GET['minprice']."' AND '".$_GET['maxprice']."'ORDER BY price DESC";
$result = mysql_query($query); 
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$address=mysql_result($result,$i,"address");
$price=mysql_result($result,$i,"price");
$ref=mysql_result($result,$i,"ref");		
echo "$price #$ref $address \n\r";
++$i;
}
}
?> </textarea>
   </td>
  </tr>
  <tr>
    <td><div align="center">
      <input type="submit" value="Submit" name="submit" />
      <?
}	

?>
    </form>

 

 

Regards

Liam

still only one result.have a look!!!

<?
include "config.php";
$db = mysql_connect($host,$login,$password);
mysql_select_db($base,$db);


if (!verifyuser() )

   { header( "Location: login.php" ); }

else {

?>
<head>
<title>Diary</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF" topmargin="5" leftmargin="5" marginheight="5" marginwidth="5" ><center>
<?
if  (isset($_POST["event_desc"])) { $event_desc = $_POST['event_desc']; }
if  (isset($_POST["submit"]) && (!isset($_POST["event_desc"]) or empty($event_desc) ))
{ ?>
<script language="Javascript" type="text/javascript">
<!--
        window.open('empty.html', '_myevent', 'HEIGHT=100,resizable=yes,WIDTH=400');

//-->
</script>
<?
}
if ( isset($_POST["submit"]) && !empty($event_desc)) {
   $eventyear = $_POST['eventyear'];
   $eventmonth = $_POST['eventmonth'];
   $eventdate = $_POST['eventdate'];
   $id = $_POST['id'];
   $day_in_a_mth = date('t', mktime(0, 0, 0, $eventmonth, 1, $eventyear)) ;

if ($day_in_a_mth >= $eventdate )
  {
   $fulldate = $eventyear."-".$eventmonth."-".$eventdate;
   $event_desc = $_POST['event_desc'];
   $id = $_POST['id'];
  $sql = "INSERT INTO event SET date='$fulldate', event_desc='$event_desc', id='$id'";
  $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
  message( "ADD EVENT", "DATA ENTERED");  }
else {
  message( "ERROR", "DATE ENTERED NOT VALID");

  }
}
else {

$query = "SELECT * FROM propertys WHERE price BETWEEN '".$_GET['minprice']."' AND '".$_GET['maxprice']."'ORDER BY price DESC";
$result = mysql_query($query); 
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$address=mysql_result($result,$i,"address");
$price=mysql_result($result,$i,"price");
$ref=mysql_result($result,$i,"ref");		

++$i;
}
}
?>

<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" name="post">
<table width="90%" class="tdborder" cellSpacing=1 cellPadding=6  border=0>
<tr>
   <td class="header" bgcolor="#6699ff"><center>Appointments</center></td></tr>
<tr>
   <td>
      <table width="100%" class=tableborder cellSpacing=1 cellPadding=0  border=0>
       <tr>
         <td><div class="genfont"><b>Date</b></div>
        		<div><select name="eventyear">
                  <option value="2007">2007
                  <option value="2008">2008
                  <option value="2009">2009
                  <option value="2010">2010
                  <option value="2011">2011
                  <option value="2012">2012
                  <option value="2013">2013
                  </select>
                  <select name="eventmonth">
                  <option value="01">Jan
                  <option value="02">Feb
                  <option value="03">Mar
                  <option value="04">Apr
                  <option value="05">May
                  <option value="06">Jun
                  <option value="07">Jul
                  <option value="08">Aug
                  <option value="09">Sep
                  <option value="10">Oct
                  <option value="11">Nov
                  <option value="12">Dec
                  </select>
                  <select name="eventdate">
                  <option value="1">1
                  <option value="2">2
                  <option value="3">3
                  <option value="4">4
                  <option value="5">5
                  <option value="6">6
                  <option value="7">7
                  <option value="8">8
                  <option value="9">9
                  <option value="10">10
                  <option value="11">11
                  <option value="12">12
                  <option value="13">13
                  <option value="14">14
                  <option value="15">15
                  <option value="16">16
                  <option value="17">17
                  <option value="18">18
                  <option value="19">19
                  <option value="20">20
                  <option value="21">21
                  <option value="22">22
                  <option value="23">23
                  <option value="24">24
                  <option value="25">25
                  <option value="26">26
                  <option value="27">27
                  <option value="28">28
                  <option value="29">29
                  <option value="30">30
                  <option value="31">31
                 </select>
                  <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
         </td>
       </tr>
     </table>
   </td>
  <tr>
   <td><div class="genfont">Enter event :</div>
       <textarea name="event_desc" rows="4" cols="15" wrap="virtual" style="width:550px; font-size:12px" tabindex="3">
R<? echo "$price #$ref $address \n";?> </textarea>
   </td>
  </tr>
  <tr>
    <td><div align="center">
      <input type="submit" value="Submit" name="submit" />
</form>     

<?
}	

?>
    


Try this mate this is the way i would code the loop through all the data.

 

<?php
include "config.php";
$db = mysql_connect($host,$login,$password);
mysql_select_db($base,$db);


if (!verifyuser()) { 
  header( "Location: login.php" );
} else {

?>
<head>
<title>Diary</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF" topmargin="5" leftmargin="5" marginheight="5" marginwidth="5" ><center>
<?php
  if  (isset($_POST["event_desc"])) { 
    $event_desc = $_POST['event_desc']; 
  }
  if  (isset($_POST["submit"]) && (!isset($_POST["event_desc"]) or empty($event_desc) )) {
?>
<script language="Javascript" type="text/javascript">
<!--
        window.open('empty.html', '_myevent', 'HEIGHT=100,resizable=yes,WIDTH=400');

//-->
</script>
<?php
}
  if ( isset($_POST["submit"]) && !empty($event_desc)) {
    $eventyear = $_POST['eventyear'];
    $eventmonth = $_POST['eventmonth'];
    $eventdate = $_POST['eventdate'];
    $id = $_POST['id'];
    $day_in_a_mth = date('t', mktime(0, 0, 0, $eventmonth, 1, $eventyear)) ;

    if ($day_in_a_mth >= $eventdate ) {
      $fulldate = $eventyear."-".$eventmonth."-".$eventdate;
      $event_desc = $_POST['event_desc'];
      $id = $_POST['id'];
      $sql = "INSERT INTO event SET date='$fulldate', event_desc='$event_desc', id='$id'";
      $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
      message( "ADD EVENT", "DATA ENTERED");  
}
    else {
      message( "ERROR", "DATE ENTERED NOT VALID");
    }
  }
  else {
    $query = mysql_query("SELECT * FROM propertys WHERE price BETWEEN '".$_GET['minprice']."' AND '".$_GET['maxprice']."'ORDER BY price DESC") or die('ERROR selecting propertys: '.mysql_error());
?>

<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" name="post">
<table width="90%" class="tdborder" cellSpacing=1 cellPadding=6  border=0>
<tr>
   <td class="header" bgcolor="#6699ff"><center>Appointments</center></td></tr>
<tr>
   <td>
      <table width="100%" class=tableborder cellSpacing=1 cellPadding=0  border=0>
       <tr>
         <td><div class="genfont"><b>Date</b></div>
        		<div><select name="eventyear">
                  ....                 </select>
                  <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
         </td>
       </tr>
     </table>
   </td>
  <tr>
   <td><div class="genfont">Enter event :</div>
       <textarea name="event_desc" rows="4" cols="15" wrap="virtual" style="width:550px; font-size:12px" tabindex="3">
       <?php
    while ($result=mysql_fetch_array($query)) {
      echo $result['price'].' #'.$result['ref'].' '.$result['address']."\n";
    }
   ?></textarea>
   </td>
  </tr>
  <tr>
    <td><div align="center">
      <input type="submit" value="Submit" name="submit" />
      <?
  }
}
?>
    </form>

 

 

Regards

Liam

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.