Jump to content

PHP echo entire table w/ passed variable


stlshawgo

Recommended Posts

I actually asked a question here yesterday and decided to try a different route with it.  What I am doing is passing an email variable entered from my home page on to www.dollapal.com/offerlist.php.  I'm wanting this page to be a complete list of all of my entries in my surveys table.  The email variable needs to be appended to the end of every link.  I got that to work, but what I want to do now is display that information for every record in my 'surveys' table.

 

Right now I am using the random function, which I'm sure is wrong, but I'm not sure what function to be looking for.

 

Is it possible to use a foreach function here to echo each record?  If so, I'm not sure how exactly to call the foreach() function in this case.

 

I believe my two problems lie in the random and foreach functions, but I'm not sure how to correct them.  I've attached a little chunk of code that I'm working with.  I'm not sure if I'm completely off base here, or if I'm close to achieving my desired result.  Please let me know if you require more information.

 

This forum has been amazing to me so far.  Thank you all for your help!

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Does anyone have any tips on this?  I was able to echo ONE record exactly how I want it to appear.  Unfortunately it's using the random function, and I want every record in my "surveys" table to be displayed.

 

I don't know if there is some sort of loop that I may be able to use for this, if it is possible?

 

Thanks!

Link to comment
Share on other sites

very simple example of listing all entries

<?PHP
/* make database connect here */

/* now the query */
$query = "SELECT * FROM tablename_here";
$result = mysql_query($query);

/* now loop thru the results */
while($row=mysql_fetch_array($result)) {
  echo $row['field_name_here'] . "<br>";
}

Link to comment
Share on other sites

Thank you for the response.  I've tried out the code that you have provided, but I'm getting an error. 

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/dollapal/public_html/offerlist.php on line 41

 

Line 41 is my echo statement.  I know it's probably syntax related, but I have no idea what I did here, or if what I'm going for is even possible.  Please let me know if you have an suggestions.  Here's a snippet of the code I'm working on so far:

 

  <?php
include("database.php");
session_start();
$email = $_SESSION['email'];
/* now the query */
$query = "SELECT * FROM surveys";
/* now loop thru the results */
while($row=mysql_fetch_array($result)) {
  echo "<b><a href=\"" . $row['url'] . $email . "\">$row['title']</a></b> . " - " . "$" . $row['pay'] . " - " . $row['info'] . "<br>"";
}
/* 0 is ID
/* 1 is title
/* 2 is info
/* 3 is pay
/* 4 is url
?>

 

Any ideas what I've missed here? 

 

Thanks!

 

Link to comment
Share on other sites

Try:

<?php
include("database.php");
session_start();
$email = $_SESSION['email'];
/* now the query */
$query = "SELECT * FROM surveys";
/* now loop thru the results */
while($row=mysql_fetch_array($result)) {
  echo "<b><a href=\"{$row['url']}{$email}\">{$row['title']}</a></b> -  \${$row['pay']} - {$row['info']}<br />";
}
/* 0 is ID
/* 1 is title
/* 2 is info
/* 3 is pay
/* 4 is url
?>

Link to comment
Share on other sites

Well I'm getting a different error now, so that's a plus.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/dollapal/public_html/offerlist.php on line 40

 

Thank you for the help!

 

EDIT:  I forgot to define the $result variable on the second go round.  Thank you all for the help!  I'm very close to what I'm going for.  I really appreciate this!

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.