Reputation: 31
<?php
$result = mysql_query("MYSQL query" );
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$rows = mysql_fetch_row($result);
echo $row[0]; // id
echo $row[20]; // the extra_info field
?>
The above query returned the full extra_info field which is as below
http://example.com/ext/lib/exe/process.php?t=87458+52&w=466&h=471&:forum_pic:queue_hasb_bunny_khd_tyun_02300.jpg, Imm processing,http://example.com/storage/high resolution/i-white bunny-tyun.jpg,only cash payment,process after christmas, handle with care notification, date: 2-5-2015
But I only needed the image urls so did the following
$extraFieldData = explode(',', $row[20]);
echo $extraFieldData[0];
echo $extraFieldData[2];
It works fine, but not at all times the extra_info field will contain the image urls in the same place as $extraFieldData[0] and $extraFieldData[2] so how to check for the image url in the result query without mentioning their position ?
Upvotes: 0
Views: 52
Reputation: 7447
If you can determine some distinguishing characteristic that an image url string will always contain, you can just check for that characteristic in each element of your array. For instance, if you new that an elements you are looking for will always contain "http", you could do something like this:
$extraInfo = "http://example.com/ext/lib/exe/process.php?t=87458+52&w=466&h=471&:forum_pic:queue_hasb_bunny_khd_tyun_02300.jpg, Imm processing,http://example.com/storage/high resolution/i-white bunny-tyun.jpg,only cash payment,process after christmas, handle with care notification, date: 2-5-2015";
$extraFieldData = explode(',', $extraInfo);
$images = array();
foreach($extraFieldData as $efd) {
if (strpos($efd, 'http') !== false) {
$images[] = $efd;
}
}
(If searching for "http" doesn't work for your situation, you can look for some other distinguishing characteristic - like the file extension.)
Upvotes: 2