Jump to content

If Empty Echo / Else Echo


justlukeyou

Recommended Posts

Hi,

 

I have a code which displays the events that users have created. However if they have not created an event it shows the empty DIV cells. So I am trying to display a message "You have no events. Create an event." if the user has not created an events. I can get this to work if against the users login but I cant seem to be able to check with the cell is empty.

 

I think I almost have it. Can anyone please advise how I complete it?

 

So far it displays "You have no events. Create an event." Regardless of whether there is content in the database or not.

 

<?php
$query = "SELECT * FROM eventjobs WHERE organiserid = " . intval($_SESSION['userID']) . " LIMIT 10";
if ($result = mysql_query($query)) 


   if (empty($organiserid))

{
 echo 'You have no events.  Create an event.';





} else {



               $row = mysql_fetch_array($result);
	{
               ?>
<div class="eventjoblistings">
<div class="boardeventfield">
<div class="boardeventfieldintro">
			    <div class="boardeventdatatitle">
			<?php echo (!empty($row['eventname'])) ? $row['eventname'] : ''; ?>
			</div>
			    <div class="boardeventdata">
			<?php echo (!empty($row['eventdetails'])) ? $row['eventdetails'] : ''; ?>
			</div>
			    <div class="boardeventdatahalf">
			<?php echo (!empty($row['eventlocation'])) ? $row['eventlocation'] : ''; ?>,
			</div>
			    <div class="boardeventdatahalf">
			<?php echo (!empty($row['eventcountry'])) ? $row['eventcountry'] : ''; ?>
			</div>
			</div>
							 <div class="boardeventfielddetails">
			    <div class="boardeventdatasupplier">
			<?php echo (!empty($row['supplier1'])) ? $row['supplier1'] : ''; ?>
			</div>
			    <div class="boardeventdata">
			<?php echo (!empty($row['supplierdetails1'])) ? $row['supplierdetails1'] : ''; ?>
</div>				
			    <div class="boardeventdata">
<?php echo (!empty($row['budget1'])) ? $row['budget1'] : ''; ?>
</div>
</div>
											 <div class="boardeventfielddetails">
			    <div class="boardeventdata">
			<?php echo (!empty($row['supplier2'])) ? $row['supplier1'] : ''; ?>
			</div>
			<?php echo (!empty($row['details2'])) ? $row['details2'] : ''; ?>			
<div class="boardeventdata">
<?php echo (!empty($row['budget2'])) ? $row['budget2'] : ''; ?>
</div>
</div>
</div>
				</div>

										<?php
						        }
} 
}			

							?>

 

 

 

 

Link to comment
Share on other sites

Hi,

 

I haven't yet but when I just run a query it works fine.

 

Do I need to say that the organiserid is at standard "0". So if ID 350 is entered then this is different so it will display everything?

 

Or would I say its blank?

 

So this would echo the eventname.

 

   <?php
$query = "SELECT * FROM eventjobs WHERE organiserid = " . intval($_SESSION['userID']) . " LIMIT 10";
if ($result = mysql_query($query)) {

               $row = mysql_fetch_array($result);
       {
               ?>
                      <div class="eventjoblistings">
                <div class="boardeventfield">
                <div class="boardeventfieldintro">
                   <div class="boardeventdatatitle">
               <?php echo (!empty($row['eventname'])) ? $row['eventname'] : ''; ?>

Edited by justlukeyou
Link to comment
Share on other sites

Hi,

 

I haven't yet but when I just run a query it works fine.

 

Do I need to say that the organiserid is at standard "0". So if ID 350 is entered then this is different so it will display everything?

 

Or would I say its blank?

 

So this would echo the eventname.

 

<?php
$query = "SELECT * FROM eventjobs WHERE organiserid = " . intval($_SESSION['userID']) . " LIMIT 10";
if ($result = mysql_query($query)) {

$row = mysql_fetch_array($result);
{
?>
<div class="eventjoblistings">
<div class="boardeventfield">
<div class="boardeventfieldintro">
<div class="boardeventdatatitle">
<?php echo (!empty($row['eventname'])) ? $row['eventname'] : ''; ?>

 

if ($result = mysql_query($query)) {

 

Will always return false, seeing as you haven't assigned anything to $result.

Link to comment
Share on other sites

Stab in the dark, but try this:

 

<?php
$query = "SELECT * FROM eventjobs WHERE organiserid = " . intval($_SESSION['userID']) . " LIMIT 10";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if (empty($result))
{
echo 'You have no events. Create an event.';
} else {
?>
<div class="eventjoblistings">
<div class="boardeventfield">
<div class="boardeventfieldintro">
						 <div class="boardeventdatatitle">
						 <?php echo (!empty($row['eventname'])) ? $row['eventname'] : ''; ?>
						 </div>
								 <div class="boardeventdata">
						 <?php echo (!empty($row['eventdetails'])) ? $row['eventdetails'] : ''; ?>
						 </div>
								 <div class="boardeventdatahalf">
						 <?php echo (!empty($row['eventlocation'])) ? $row['eventlocation'] : ''; ?>,
						 </div>
								 <div class="boardeventdatahalf">
						 <?php echo (!empty($row['eventcountry'])) ? $row['eventcountry'] : ''; ?>
						 </div>
						 </div>
															 <div class="boardeventfielddetails">
								 <div class="boardeventdatasupplier">
						 <?php echo (!empty($row['supplier1'])) ? $row['supplier1'] : ''; ?>
						 </div>
								 <div class="boardeventdata">
						 <?php echo (!empty($row['supplierdetails1'])) ? $row['supplierdetails1'] : ''; ?>
</div>						
								 <div class="boardeventdata">
<?php echo (!empty($row['budget1'])) ? $row['budget1'] : ''; ?>
</div>
</div>
																							 <div class="boardeventfielddetails">
								 <div class="boardeventdata">
						 <?php echo (!empty($row['supplier2'])) ? $row['supplier1'] : ''; ?>
						 </div>
						 <?php echo (!empty($row['details2'])) ? $row['details2'] : ''; ?>					
<div class="boardeventdata">
<?php echo (!empty($row['budget2'])) ? $row['budget2'] : ''; ?>
</div>
</div>
</div>
								 </div>

																				 <?php
																 }


														 ?>

Edited by Beeeeney
Link to comment
Share on other sites

Hi,

 

This work..If I say its greater than zero.

 

$organiserid = 0;

$query = "SELECT * FROM eventjobs WHERE organiserid = " . intval($_SESSION['userID']) . " LIMIT 10";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if ($organiserid > 0)
{
 echo 'You have no events.  Create an event.';
} else {
{

Link to comment
Share on other sites

Hi,

 

This work..If I say its greater than zero.

 

$organiserid = 0;

$query = "SELECT * FROM eventjobs WHERE organiserid = " . intval($_SESSION['userID']) . " LIMIT 10";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if ($organiserid > 0)
{
echo 'You have no events. Create an event.';
} else {
{

 

But $organiserid IS 0. You told your code that it is 0.

 

I hope you find the help you need!

Link to comment
Share on other sites

There are several issues with that code, not the least of which is indentation (which could be the fault of the "WYSIWYG" editor).

 

Here is an outline (using your code) of how you can accomplish this.

$query = "SELECT * FROM eventjobs WHERE organiserid = " . intval($_SESSION['userID']) . " LIMIT 10";

/* This assigns the resource (or FALSE) to $result AND tests if the query succeeded
   NOTE: The query WILL succeed if there are NO ROWS found */
if ($result = mysql_query($query)) { 
   // if (empty($organiserid)) # As you have seen this is not useful

   // Check to see if there were ZERO rows returned
   if (mysql_num_rows($result) == 0) {
       echo 'You have no events.  Create an event.';
   } else {
       /* You were only processing the first row. You need a while loop */
       // $row = mysql_fetch_array($result);
       while ($row = mysql_fetch_assoc($result)) {
?>
<div class="eventjoblistings">

   AND SO FORTH

</div>
<?php 
       } // END while ($row =
   }     // END if (mysql_num_rows (
} // END if ($result = mysql_query(

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.