Jump to content

Results from Db outputted twice


runnerjp

Recommended Posts

Hey guys.. for come reason my data is outputted twise shown in the image below and i cant figure out why.

 

error66.jpg

 

<html>
<head>
<title>Month Summary</title>

<!-- change styles if you want -->
<style type="text/css">
p {font-family: georgia, verdana, sans-serif; font-size: 13px; color: #333333; }
h1 {font-family: georgia, verdana, sans-serif; font-size: 16px; color: #26618e; }
body {background-color: #fcfcfc;}
</style>
</head>
<body>
<br/>

<?php

// THERE IS NO NEED TO EDIT BELOW HERE

$mon = $_GET['mon']; // month from clicked month name
$month = intval($mon); // var to use with month name array
if (strlen($mon)==1) { $mon = "0". $mon; }
$yr = $_GET['yr']; // year from clicked month name

include("cal_parms.php");
include("./lang/dat_nam_en.php"); // load default language file so as not to mess anything upp with new text.
include($dat_names); // retrieved from cal_parms.php as a 'language' file
include("cal_db_conn.php");
mysql_connect($db_host, $db_login, $db_pass) or die ("Can't connect!"); 
mysql_select_db($db_name) or die ("Can't open database!");

$min_dat = $yr. "-". $mon. "-01";
$max_dat = $yr. "-". $mon. "-31"; //sloppy but effective

// retrieve all events for the month
$query = "SELECT * from $db_table WHERE (ev_dat>='$min_dat') AND (ev_dat<='$max_dat') ORDER by ev_dat"; 
$result = @mysql_db_query($db_name, $query); 
echo "<table width='480' cellpadding='3' cellspacing='3' align='center' style='border: thin dotted #999999;' bgcolor='#f7f7f7'><tr><td>";

while ($myrow = mysql_fetch_array($result)) // loop through all results
{
    $found = $myrow['ev_dat'];
    $pieces = explode("-", $found);
    $monum = intval($pieces[1]);
    $danum = intval($pieces[2]);
    echo "<h1>". $danum. " ". $mo[$month]. ", ". $yr. "</h1>";
    echo "<p><strong>". $EventText. ": ". $myrow['ev_title']. "</strong><br/>";
    echo $LocationText. ":  ". $myrow['ev_locn']. "<br/>";
    echo $DetailsText. "<br/>". nl2br($myrow['ev_desc']). "</p>";
    $i++;
}
if ($i==0) { echo "<h1>".$noEventsText." ". $mo[$month]. "</h1>"; }
if ($sho == "1") {
    echo "<p align='right'><a href='javascript:self.close()'>".$closewindowText ."</a>";
}
else {
    echo "<p align='right'>« <a href='javascript:history.go(-1)'>".$backToCalendar."</a></p>";
}
?>
</td></tr></table>
</html>
</body>

 

hopefully someone can see the reason why

 

Thanks

Link to comment
Share on other sites

You are either including the posted file twice or it is inside of a loop that executes twice. The fact that you have variables $i and $sho that are not initialized in the posted code but are used and cause the back/close links to be produced indicate the problem is in the code that is causing the posted code to be executed.

Link to comment
Share on other sites

I just cant find where its going wrong... its also doing it for this code which poicks dates rather then month

 

<html>
<head>
<title>Event Information</title>

<!-- change styles if you want -->
<style type="text/css">
p {font-family: georgia, verdana, sans-serif; font-size: 13px; color: #333333; }
h1 {font-family: georgia, verdana, sans-serif; font-size: 16px; color: #26618e; }
body {background-color: #fcfcfc;}
</style>
</head>
<body>
<br />

<?php
// no need to edit below here
$id = $_GET['event']; // from clicked day
$sho = $_GET['sho']; // display method

// mo/yr needed as well for whole month view

include("cal_parms.php");
include($dat_names); // retrieved from cal_parms.php as a 'language' file
include("cal_db_conn.php");
mysql_connect($db_host, $db_login, $db_pass) or die ("Can't connect!"); 
mysql_select_db($db_name) or die ("Can't open database!");

// retrieve record for 'clicked' days
$query = "SELECT * FROM $db_table WHERE id = '$id' "; // retrieves ONE record
$result = mysql_db_query($db_name, $query); 
$myrow = mysql_fetch_array($result);
$ev_1 = $myrow['ev_dat']; // is date for that record (allows multiple events selection)

$found = $myrow['ev_dat'];
$pieces = explode("-", $ev_1);
$monum = intval($pieces[1]);

$query = "SELECT * from $db_table WHERE ev_dat = '$ev_1' "; // retrieves ALL date matches
$result = mysql_db_query($db_name, $query); 
echo"<table width='480' cellpadding='3' cellspacing='3' align='center' style='border: thin dotted #cccccc;' bgcolor='#f7f7f7'><tr><td>";
echo "<h1>". $mo[$monum]. " ". intval($pieces[2]). ", ". intval($pieces[0]). "</h1>";

while ($myrow = mysql_fetch_array($result)) // loop through all results
{
    echo "<p><strong> Title: ". $myrow['ev_title']. "</strong></p>";
   // echo "<p>". $LocationText. ": ". $myrow['ev_locn']. "</p>";
    echo "<p>". nl2br($myrow['ev_desc']). "</p><br/>";
}

?>
</td></tr></table>
</html>
</body>

Link to comment
Share on other sites

Posting a second set of code without posting the corresponding output is not really going to help, either with the problem the second code is having or with the first code and its' problem. Stick to one problem at a time.

 

Look at the "view source" in your browser for the first problem you posted. You will probably find what I already suggested, that you are somehow including/looping through that code twice on one page.

 

 

Link to comment
Share on other sites

Humm it seems the code event runs before the loop and doubles itself

 

<?php $query = "SELECT * from $db_table WHERE (ev_dat>='$min_dat') AND (ev_dat<='$max_dat') ORDER by ev_dat"; 
$result = @mysql_db_query($db_name, $query); 
echo "<table width='480' cellpadding='3' cellspacing='3' align='center' style='border: thin dotted #999999;' bgcolor='#f7f7f7'><tr><td>"; ?>

 

even the above taken form the top code so it dont see where im psting it twice nor looping it twice

 

 

Link to comment
Share on other sites

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.