Forum Moderators: coopster

Message Too Old, No Replies

Array Assistance

Need to convert results to insert in mysql table

         

5x54u

9:52 pm on Jun 29, 2005 (gmt 0)

10+ Year Member



I need to insert the reults of this below into a Mysql table. I am having difficulty getting the array and sql sentence correct. Any help would be very appreciaited. TY in advance

$match_result = 
preg_match_all('/<\s*a\s*href=\"([^\"]+)\"\s*id=r-[0-9]_[0-9]([^\"]+)>/i',
$page_contents,
$match_array,
PREG_SET_ORDER);
foreach ($match_array as $entry) {
$href = $entry[1];
$anchortext = $entry[2];

5x54u

7:29 pm on Jun 30, 2005 (gmt 0)

10+ Year Member



<*>Sorry for the bump<*>

I may have asked the wrong question. I need some assistance with creating a for each loop to insert the above code into a table with each instance of the element having its own row in the table.

ergophobe

10:01 pm on Jun 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As in

foreach ($match_array as $entry) {
$href = $entry[1];
$anchortext = $entry[2];
$query = "INSERT INTO elements (eid, href, anchortext) VALUES (NULL, '$href', '$anchortext')";
mysql_query($query);
}

You might want to add some error checking, and "or die" clause or something like that, but that should give you the basics.

5x54u

3:12 am on Jul 1, 2005 (gmt 0)

10+ Year Member



Thank you that did it. I was brain farting on simply putting the sql in the for each. I was trying to make a new for each. 5x5 hits himself with hammer DOH