stlshawgo Posted November 14, 2010 Share Posted November 14, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/218642-php-echo-entire-table-w-passed-variable/ Share on other sites More sharing options...
stlshawgo Posted November 14, 2010 Author Share Posted November 14, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/218642-php-echo-entire-table-w-passed-variable/#findComment-1134197 Share on other sites More sharing options...
litebearer Posted November 15, 2010 Share Posted November 15, 2010 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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/218642-php-echo-entire-table-w-passed-variable/#findComment-1134543 Share on other sites More sharing options...
stlshawgo Posted November 17, 2010 Author Share Posted November 17, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/218642-php-echo-entire-table-w-passed-variable/#findComment-1135298 Share on other sites More sharing options...
jcbones Posted November 17, 2010 Share Posted November 17, 2010 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/218642-php-echo-entire-table-w-passed-variable/#findComment-1135312 Share on other sites More sharing options...
stlshawgo Posted November 17, 2010 Author Share Posted November 17, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/218642-php-echo-entire-table-w-passed-variable/#findComment-1135321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.