For the sake of everyone reading this thread, below is the same code as posted by SimplyHiredGuy, the only change is using the forum's PHP tags and indentions using tabs - the line numbers are the SAME.
<?php
if($rawJobs2Host == "PRODUCTIONRAWJOBS")
{
//user wants to browse, get browsable fields list
$browseFields = $_POST['browseFields'];
//create SQL query for browsing
$browseQuery = "SELECT ";
for($i = 0; $i < count($browseFields); $i++)
{
if($i == (count($browseFields) - 1))
{
if($browseFields[$i] == "detail_page_html")
$browseQuery .= "SUBSTRING(detail_page_html, 0, 10)";
else
$browseQuery .= $browseFields[$i];
}
else
{
if($browseFields[$i] == "detail_page_html")
$browseQuery .= "SUBSTRING(detail_page_html, 0, 10),";
else
$browseQuery .= $browseFields[$i].",";
}
}
$dbConnection = DB::connect("mysql://$rawJobs2User:$rawJobs2Pass@$rawJobs2Host/$rawJobs2Db");
$resultSet = $dbConnection->query($browseQuery);
if(DB::isError($resultSet))
{
$dbConnection->disconnect();
echo "The following error occured while trying to query the database: <br>";
die($resultSet->getUserInfo());
}
while($row = mysql_fetch_row($resultSet))
{
if(DB::isError($row))
{
$dbConnection->disconnect();
echo "The following error occured while trying to fetch site records from the database: <br>";
die($row->getUserInfo());
}
echo "$row <br>";
}
}
?>
I believe jonabomer's post might have some misleading points in it, let me share what I know:
in the mean time the rest is pretty confusing to me - I've never seen DB::connect(); before are you using MySQL or something else because to do this I use mysql_connect();
PEAR :: Manual :: DB::connect()
a couple of other things $browsefields starts out as an item in your POST array but later you treat it as an array itself, it it a list of radio buttins or something, it doesnt feel right looking at this code
If you'll note this line:
$browseFields = $_POST['browseFields'];
you can see he defines the variable and fills in the value with the POST'd value. It's easier to type "browseFields" than "_POST['browseFields']" !
also lastly your loop are you looping up or down because you have the breaking condition of the loop as $i<count($browseFields) but then you increment $i with i++
Either you aren't familiar with for() loops, or you misinterpreted his code. To me, the for() loop looks fine. $i starts out as 0, and as long as it is less than the number of fields contained in the array 'browseFields' it will work fine. I would agree with you, however, that it seems strange to treat the POST element as an array. Though there are certain ways that this situation can happen, I think SimplyHiredGuy needs to clarify and tell us exactly what is the 'browseFields' POST'd element.