Jump to content

[SOLVED] Can't I have 2 queries on a page?


drums

Recommended Posts

I created a new dB that is simpler with 13 fields but there must be a conflict because I get no errors or data.

So I make a query for each of the 5 data entry spots on the page. Do I need to close it or something? I can't figure what else the problem could be...

<? 
$query = mysql_query("select * from xlsdata where spot='1st'") or die("SQL error: " . mysql_error());if (FALSE === ($record = mysql_fetch_array($query))){    
} 
?>
<h2><?php echo $record['date-event']; ?></h2>
<p><?php echo $record['beginning']; ?>
<blockquote>
<?php if(!empty($record['bullet1'])) echo "<li>".$record['bullet1']."</li>"; ?>
    <?php if(!empty($record['bullet2'])) echo "<li>".$record['bullet2']."</li>"; ?>
    <?php if(!empty($record['bullet3'])) echo "<li>".$record['bullet3']."</li>"; ?>
    <?php if(!empty($record['bullet4'])) echo "<li>".$record['bullet4']."</li>"; ?>
    <?php if(!empty($record['bullet5'])) echo "<li>".$record['bullet5']."</li>"; ?> 
    <?php if(!empty($record['bullet6'])) echo "<li>".$record['bullet6']."</li>"; ?>
    <?php if(!empty($record['bullet7'])) echo "<li>".$record['bullet7']."</li>"; ?>
    <?php if(!empty($record['bullet8'])) echo "<li>".$record['bullet8']."</li>"; ?>
    <?php if(!empty($record['bullet9'])) echo "<li>".$record['bullet9']."</li>"; ?>
    </blockquote>
<?php echo $record['end']; ?></p>

<? 
$query = mysql_query("select * from xlsdata where spot='2nd'") or die("SQL error: " . mysql_error());if (FALSE === ($record = mysql_fetch_array($query))){    
} 
?>
<h2><?php echo $record['date-event']; ?></h2>
<p><?php echo $record['beginning']; ?>
<blockquote>
<?php if(!empty($record['bullet1'])) echo "<li>".$record['bullet1']."</li>"; ?>
    <?php if(!empty($record['bullet2'])) echo "<li>".$record['bullet2']."</li>"; ?>
    <?php if(!empty($record['bullet3'])) echo "<li>".$record['bullet3']."</li>"; ?>
    <?php if(!empty($record['bullet4'])) echo "<li>".$record['bullet4']."</li>"; ?>
    <?php if(!empty($record['bullet5'])) echo "<li>".$record['bullet5']."</li>"; ?> 
    <?php if(!empty($record['bullet6'])) echo "<li>".$record['bullet6']."</li>"; ?>
    <?php if(!empty($record['bullet7'])) echo "<li>".$record['bullet7']."</li>"; ?>
    <?php if(!empty($record['bullet8'])) echo "<li>".$record['bullet8']."</li>"; ?>
    <?php if(!empty($record['bullet9'])) echo "<li>".$record['bullet9']."</li>"; ?>
    </blockquote>
<?php echo $record['end']; ?></p>
<? 
$query = mysql_query("select * from xlsdata where spot='3rd'") or die("SQL error: " . mysql_error());if (FALSE === ($record = mysql_fetch_array($query))){    
} 
?> ... to spot='5th'

 

Link to comment
Share on other sites

You have short tags ("<?") around the queries but full tags ("<?php") around the other code.  It may be that your server is configured not to allow short tags.  In that case, they are being ignored by the PHP processor and sent to the browser. The browser will ignore them because they are an unknow HTML tag (since they start with "<").

 

Always use full tags ... <?php

 

Also, turn on error reporting so you can see any errors you get.

 

So the beginning of every php file should be:

<?php
error_reporting(E_ALL);

Link to comment
Share on other sites

Try the following...

<?php
$spots = array ("1st","2nd","3rd","4th","5th");
foreach($spots as $spot) {
$query = mysql_query("select * from xlsdata where spot='$spot'") or die("SQL error: " . mysql_error());
$record = mysql_fetch_array($query);
$count = mysql_num_rows($query);
?>
Returned <h2><?php echo $count; ?></h2> Rows
<h2><?php echo $record['date-event']; ?></h2>
<p><?php echo $record['beginning']; ?>
<blockquote>
   <?php if(!empty($record['bullet1'])) echo "<li>".$record['bullet1']."</li>"; ?>
    <?php if(!empty($record['bullet2'])) echo "<li>".$record['bullet2']."</li>"; ?>
    <?php if(!empty($record['bullet3'])) echo "<li>".$record['bullet3']."</li>"; ?>
    <?php if(!empty($record['bullet4'])) echo "<li>".$record['bullet4']."</li>"; ?>
    <?php if(!empty($record['bullet5'])) echo "<li>".$record['bullet5']."</li>"; ?>
    <?php if(!empty($record['bullet6'])) echo "<li>".$record['bullet6']."</li>"; ?>
    <?php if(!empty($record['bullet7'])) echo "<li>".$record['bullet7']."</li>"; ?>
    <?php if(!empty($record['bullet8'])) echo "<li>".$record['bullet8']."</li>"; ?>
    <?php if(!empty($record['bullet9'])) echo "<li>".$record['bullet9']."</li>"; ?>
    </blockquote>
<?php echo $record['end']; ?></p>
<?php
}
?>

 

Tbh the only changes where to put everything into one place instead of duplicating code and i added a line to show how many (if any) rows where returned.. This should ensure you are getting a return from mysql, also as DavidAM says make sure the correct error report levels are set and short tags are phrased..

 

Stuie

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.