PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi,
why does the code below return " array: , , , , , , , , , , , , , , , , , , , " ?
the num_rows returned is 1 and i'm only querying 10 columns so the maximum number of values in the array should be no more than this.
when i try to remove the empty values using the loop, it makes no difference either.
what am i doing wrong and why are there so many values in the $row array?
/***********get db record for the current current pub crawl ***************/
db_connect();
$sql = mysql_query("SELECT e1,e2,e3,e4,e5,e6,e7,e8,e9,e10 from Pub_Crawl_Order
WHERE crawlID = $crawl_id")
or die ('query1 invalid on table_data.php: ' . mysql_error() );
$row = mysql_fetch_array($sql); //creat array of the record
/*****remove empty values from array********/
foreach ($row as &$val) {
if ($val == 'NULL' || '') {
unset($val);
}
}
$a = implode(", ", $row ); //test code
print 'array values: ' . $a;
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
thanks hrubos, but that doesn't really explain why i'm getting the result i described.
i was actually hoping to get rid of the e1, e2 .. and use select *. there's only 11 columns in the table: the first is the index key and the others are the e1,e2,e3.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not recieve a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
<?php
/***********get db record for the current current pub crawl ***************/
// I'm assuming this is your database connection
db_connect();
// Run a query on 10 fields in the Pub_Crawl_Order table fetching records in the table that have a crawlID of $crawl_id
$sql = mysql_query("SELECT e1,e2,e3,e4,e5,e6,e7,e8,e9,e10 from Pub_Crawl_Order
WHERE crawlID = $crawl_id")
or die ('query1 invalid on table_data.php: ' . mysql_error() );
// Assign the last row of the result into a vaiable called row
$row = mysql_fetch_array($sql); //creat array of the record
/*****remove empty values from array********/
// Loop the one record row array looking at a reference to the member values
foreach ($row as &$val) {
// THIS SYNTAX LOOKS WONKY,
// If $val is equal to the string 'NULL' OR [empty] :: THIS WILL NOT EVALUATE HOW YOU THINK IT WILL
if ($val == 'NULL' || '') {
// Make $val an unset value
unset($val);
}
}
// What are you hoping to do here?
$a = implode(", ", $row ); //test code
// You could always do a var_dump of the array, no?
print 'array values: ' . $a;
?>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
this is what i was after. i get a bit narky if i can't write the code the same way as i have in my pseudocode. anyway seems to work well.
basiclly this script is a response to an ajax call (no the actual xmlhttp response, as yet) by my google maps application.
if ($_GET['action'] == 'addpub')
{
$crawl_id = $_GET['crawlid'];
$pub_id = $_GET['pubid'];
/***********get db record for the current current pub crawl **********************/
db_connect();
$sql = mysql_query("SELECT * from Pub_Crawl_Order
WHERE crawlID = $crawl_id")
or die ('query1 invalid on table_data.php: ' . mysql_error() );
$row = mysql_fetch_assoc($sql); //creat array of the record
/*****remove index key and empty values from array********/
unset($row['crawlID']);
foreach ($row as $key => &$val) {
if ($val == 'NULL' || $val =='') {
unset($row[$key]);
}
}
/**** declare next empty column in Pub_Crawl_Order ******/
$list_count = count($row);
$i = $list_count + 1;
$next_col = 'e' . $i;
//echo $next_col;
/****** add pub to db ***********************************/
$sql2 = mysql_query("UPDATE Pub_Crawl_Order
SET $next_col = $pub_id
WHERE crawlID = $crawl_id");
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]