-
Posts
45 -
Joined
-
Last visited
Never
Posts posted by wattsup88
-
-
Fatal error: [] operator not supported for strings in /home/content/d/i/a/dianabarton/html/tests/session1.php on line 38
-
Is this the right idea? b/c as strange as it sounds it worked the first time but after that it gives me the same message... here's the code:
[code]
$result = mysql_query("SELECT * FROM jobs ORDER BY id");
$_SESSION['id'] = "$id";
$_SESSION['id'] = array();
echo "<table>";
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$_SESSION['id'][] = $id;
echo "<tr><td width=\"200\">$id</td>";
echo "<td width=\"200\"><a href=\"session2.php\">View Job</a></td></tr>";
}
echo "</table>";
?>
[/code]
-
I need to know how to make a multidimensional array from $_SESSION element but for some reason php thinks it is a string... wonering if anyone has a better way to do this...
[code]$result = mysql_query("SELECT * FROM jobs ORDER BY id");
echo "<table>";
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$_SESSION['id'][] = $id;
echo "<tr><td width=\"200\">$id</td>";
echo "<td width=\"200\"><a href=\"session2.php\">View Job</a></td></tr>";
echo "</table>";
?>[/code]
Thanks
-Jake
-
oh and i used the foreach statement that crayon violet gave me in the post before my last one...
-
I keep getting this message:Warning: Invalid argument supplied for foreach() ... obviously wrong for each statement but i dont know why...
-
Give your code so I (and other people) can try and help you out... If you don't post code its hard to help ya... Also, I am pretty sure the arutha code is right... but again im no expert...
-
One more question... How do i return the value clicked on the next page...
-
Ok I was just wondering how to achieve this goal... I need to pass a row returned from mysql to a variable then to another page after its clicked on... I have tried two methods... The $SESSION method and the $_POST method... Both return the last value of the row and not the actual row im clicking on... Here is the code for the $_POST method
post1.php:
[code]
<form name="viewjobs" action="post2.php>
<?php
$result = mysql_query("SELECT * FROM jobs ORDER BY id");
//query displayed
while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
print "<table border=\"1\">";
print "<tr>";
print "<td width=\"200\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"submit\" value=\"View Job\">";
print "<td width=\"200\">$id";
print "</td>";
print "</table>";
}
?>
</form>
[/code]
post2.php:
[code]<?php
echo $_POST['id'];
?>[/code]
It posts the value "8" as that is the last value of the table... The next method does the same thing... However, keep in mind that I am trying to make the value of the row "clicked on" appear on the next page...Here is the $_SESSION method used...
session1:
[code]<a href="session2.php">Click Here</a>
<?php
$result = mysql_query("SELECT * FROM jobs ORDER BY id");
//query displayed
while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
print "<table border=\"1\">";
print "<tr>";
print "<td width=\"200\">$_SESSION['id'] = "$id";
print "<td width=\"200\">$id";
print "</td>";
print "</table>";
}
?>[/code]
session2:
[code]<?php
echo $_SESSION['id'];
?>[/code]
As i stated earlier it returns the value "8"... My best guess is that the variable is overritten every time a value from the database is returned and the last value written is the last value in the table... If anyone has a method that would be functional that would be fantistic... i know i posted something about this before but now its a little more specific so you can understand...
Thanks in advance
-Jake -
I would love to try and help you but you need to display the current code you are having problems with... and what your trying to do with it... I'm sorry arutha wasn't of much help... it did help me tho so i thought id pass that along... The code arutha puts out tho is not incorrect... at least i cant find anything wrong with it...
-
yeah i agree books help conect areas that tutorials cannot... However, the tutorial that i was speaking of was on making queries the address is...http://preview.arutha.co.uk/viewtut/18/
-
you dont code things into the db you code them in your html page that you display using php...
-
It depens on the server... my server i can put it anywhere... do you even have php installed for sure on your server?
-
Unfortunatly I am not familiar with the session() method :(... I do have the form tag, it is elsewhere on the page of code... I guess it needs to be right next to the other stuff??? However, i think ill try the session() method if anyone has some basic info on how to use it in my case that would be great... Oh and thanks everyone else for your help so far...
-
hmmm... I personally don't know i dont have a high traffic rate on my site... I don't see why there would be a problem tho... Why would php be designed that way especially since so many people use $_POST superglobal to display form results and such...
-
There is a bunch of basic knowledge that you must gain before you can just start this project... First you need to make the database that you want to pull information from... Then you have to tell your server in php of course what information to pull by making "queries"... I dont know how much you know so im starting at the beginning... There are a bunch of great tutorials out there on this matter... a few on phpfreaks.com of course but the most basic ones I've found are on this site: http://preview.arutha.co.uk/tutorials/PHP/All/1/1/... As i said earlier the first thing is making a database so do that first... I hope that gave you a direction to head in...
-
Hello all,
Of course im a noob or i wouldn't be asking for help so bear with me... I have been having trouble passing global variables page to page... My goal is to be able to pass an id number from one page to the next... here is the code...
First the form code...
//****query dispayed****//
while ($row = mysql_fetch_array($result))
{
$jbc = $row['jbcategory'];
$jbt = $row['jbtitle'];
$jbs = $row['jbsalary'];
$jbst = $row['jbstate'];
$id = $row['id'];
//alternating colors code
$row_color = ($row_count % 2) ? $color1 : $color2;
//alternating colors code
print "<tr>
<td width=\"5\" bgcolor=\"990101\" nowrap>\n";
print "<td width=\"200\" bgcolor=\"$row_color\" no wrap>".stripslashes($jbt)."</td>";
print "<td width=\"75\" bgcolor=\"$row_color\" no wrap>".stripslashes($jbc)."</td>";
print "<td width=\"75\" bgcolor=\"$row_color\" no wrap>".stripslashes($jbs)."</td>";
print "<td width=\"50\" bgcolor=\"$row_color\" no wrap>".stripslashes($jbst)."</td>";
print "<td width=\"75\" bgcolor=\"$row_color\" no wrap><input type=\"hidden\" value=\"$id\" name=\"$id\"><input type=\"submit\" value=\"View Job\"></td>";
print "<td width=\"5\" bgcolor=\"990101\" nowrap>\n";
print "</tr>\n";
$row_count++;
}
print "</table>\n";
//****query dispayed****//
Now... the result page
<?php
$value = $_POST['$id'];
$result = mysql_query("SELECT * FROM jobs WHERE id = '$value'");
//****query dispayed****//
while ($row = mysql_fetch_array($result))
{
$jbc = $row['jbcategory'];
$jbt = $row['jbtitle'];
$jbs = $row['jbsalary'];
$jbst = $row['jbstate'];
$jbdesc = $row['jbdesc'];
$jbqual = $row['jbqualifications'];
$jbco = $row['jbcompany'];
$jbcity = $row['jbcity'];
$jbstatus = $row['jbstatus'];
print "<td width=\"60\" bgcolor=\"990101\" rowspan=\"8\">\n";
print "<tr><td><strong>Job Title: </strong><br/>".stripslashes($jbt)."</td></tr>";
print "<tr><td><strong>Job Category: </strong><br/> ".stripslashes($jbc)."</td></tr>";
print "<tr><td><strong>Salary: </strong><br/> ".stripslashes($jbs)."</td></tr>";
print "<tr><td><strong>Location: </strong><br/>$jbcity, $jbst</td></tr>";
print "<tr><td><strong>Company: </strong><br/> ".stripslashes($jbco)."</td></tr>";
print "<tr><td><strong>Job Description: </strong><br/> ".stripslashes($jbdesc)."</td></tr>";
print "<tr><td><strong>Job Status: </strong><br/> ".stripslashes($jbstatus)."</td></tr>";
print "<td width=\"30\" bgcolor=\"990101\" rowspan=\"8\">\n";
print "</tr>\n";
$row_count++;
}
Thanks in advance for your help...
-Jacob -
I'm no expert, but you could use hidden inputs and the superglobal $_POST and try it that way... thats how i do it... you shoulnd't have to go through your database
[SOLVED] Multidimensional arrays
in PHP Coding Help
Posted
$result = mysql_query("SELECT * FROM jobs ORDER BY id");
echo "<table>";
$_SESSION['id'] = "$id";
$_SESSION['id'] = array();
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$_SESSION['id'][] = "$id";
echo "<tr><td width=\"200\">$id</td>";
echo "<td width=\"200\"><a href=\"session2.php\">View Job</a></td></tr>";
}
echo "</table>";
?>
[/code]