I asked this question here originally:
http://www.daniweb.com/web-development/php/threads/439484/why-arent-more-echos-being-executed
uploaded to the server(form):
http://cs4.sunyocc.edu/~j.d.dancks/onestopshop/index.php
sort_mysql results sorts arrays of other queries and returns a 2d arrays of data that was found in all of the data arrays.
EDIT: I solved the problem with echos, now I have a problem with this function (I think):
function sort_mysql_results()
{
echo "<p>begin smr</p>";
$match=array();
$c_match=0;
$num_it = 0;
$num_args = func_num_args();
$c = 0;
$args = func_get_args();
while(isset($args[0][$num_it]))
{
echo "<p>sort mysql beginning of loop</p>";
$skip=false;
$name = $args[0][$num_it]['item_name'];
$i=1;
while(isset($args[$i])&&!$skip)
{
$skip = !check($args[$i],$name);
$i++;
}
$num_it++;
if(!$skip)
{
$match[$c_match] = $args[0];
$c_match++;
}
}
echo "<p>Num args: ".$num_args.", Iterations: ".$num_it."</p>";
return $match;
}
The function gets called like this:
$match = sort_mysql_results(sort_soundex_results($queries[0]),get_array($queries[1]));
Now $match is supposed to be an array. For some reason its not. I try to print results into a table like so:
if(count($match)>0)
{
$num=0;
echo "<table>\n
<tr>\n
<td>Name</td><td>Category</td><td>Description</td>\n
</tr>\n";
while(isset($match[$num]))
{
echo "<tr>\n
<a href=\"product2.php?id=".$match[$num]['ItemID']."\"><td>".$match[$num]['item_name']."</td><td>".$match[$num]['cat_name']."</td><td>".$match[$num]['descr']."</td></a>\n
</tr>\n";
$num++;
}
echo "</table>\n";
}
else
{
echo "<p>No matches found. Go back and try different search criteria</p>\n";
}
for reference the mysql table being queried looks like:
+-------------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------------------+----------------+
| item_name | varchar(100) | NO | | | |
| ItemID | mediumint(9) | NO | PRI | NULL | auto_increment |
| cat_name | varchar(45) | NO | | | |
| userID | mediumint(9) | NO | | | |
| descr | text | NO | | | |
| image | tinytext | YES | | NULL | |
| date | timestamp | NO | | CURRENT_TIMESTAMP | |
| highest_bid | decimal(6,2) | NO | | 0.00 | |
| time_expire | timestamp | NO | | 0000-00-00 00:00:00 | |
+-------------+--------------+------+-----+---------------------+----------------+
EDIT: Hope you,re still with me. I did some further debugging:
...
if(count($match)>0)
{
echo "<p>space</p><h2>In IF STATEMENT VALUE OF MATCH BEFORE WHILE LOOP</h2><p>space</p>\n";
echo "<p>space</p><p>space</p><p>space</p>\n";
var_dump($match);
echo "<p>space</p><p>space</p><p>space</p>\n";
echo "<h2>VALUE OF match[num]</h2>\n";
echo "<p>space</p><p>space</p><p>space</p>\n";
var_dump($match[0]);
echo "<p>space</p><p>space</p><p>space</p>\n";
...
check this out:
In IF STATEMENT VALUE OF MATCH BEFORE WHILE LOOP
space
space
space
space
array(1) { [0]=> array(1) { [0]=> array(12) { ["item_name"]=> string(10) "Squat Rack" ["ItemID"]=> string(1) "8" ["cat_name"]=> string(16) "Sports Equipment" ["userID"]=> string(1) "1" ["descr"]=> string(25) "Comes with 275 lbs plates" ["image"]=> string(14) "squat_rack.jpg" ["date"]=> string(19) "2012-10-15 09:34:36" ["highest_bid"]=> string(4) "0.00" ["time_expire"]=> string(19) "2012-12-01 00:00:01" ["src"]=> string(4) "S362" ["src2"]=> string(4) "S362" ["result"]=> string(1) "1" } } }
space
space
space
VALUE OF match[num]
space
space
space
array(1) { [0]=> array(12) { ["item_name"]=> string(10) "Squat Rack" ["ItemID"]=> string(1) "8" ["cat_name"]=> string(16) "Sports Equipment" ["userID"]=> string(1) "1" ["descr"]=> string(25) "Comes with 275 lbs plates" ["image"]=> string(14) "squat_rack.jpg" ["date"]=> string(19) "2012-10-15 09:34:36" ["highest_bid"]=> string(4) "0.00" ["time_expire"]=> string(19) "2012-12-01 00:00:01" ["src"]=> string(4) "S362" ["src2"]=> string(4) "S362" ["result"]=> string(1) "1" } }
space
space
space
Looks like its supposed to. Whats going on here???
Here is the modified sort_mysql_results:
function sort_mysql_results()
{
echo "<p>begin smr</p>";
$match=array();
$c_match=0;
$num_it = 0;
$c = 0;
$args = func_get_args();
while(isset($args[0][$num_it]))
{
echo "<p>sort mysql beginning of loop</p>";
$skip=false;
$name = $args[0][$num_it]['item_name'];
$i=1;
while(isset($args[$i])&&!$skip)
{
$skip = !check($args[$i],$name);
$i++;
}
if(!$skip) //if found in another parameter
{
$match[$c_match] = $args[0][$num_it];
$c_match++;
}
$num_it++;
}
echo "<p>Num args: ".$num_args.", Iterations: ".$num_it."</p>";
var_dump($match);
return $match;
}
Basically the original only saved the one after the found query and stored the 2D array, not the single array making $match a 3D array. Thanks Madara Uchiha for posting