patrickm Posted January 25, 2008 Share Posted January 25, 2008 Although I think I got the "explode" function right, I noticed new error messages in the httpd log. Info: the script is called by using: http://www.#####.com/content/productgroep.php?hoofdgroep=1500&subgroep=0 Although the site is working fine, there are "Undefined offset: 4 in productgroep.php at line 123" messages (the number 4/relevant line number can be different, according to the 8 (0-7) options below). include("../source/config.php"); $sql = "SELECT code, uitvoering, omschrijving, subgroep FROM artikel_gegevens "; $resultaat = mysql_query($sql) or die (mysql_error()); while ($dump_gegevens = mysql_fetch_object($resultaat)) { $temp = explode (":", $dump_gegevens->subgroep); if ($temp[0] == $subgroep) { echo "<a href=\"producten.php?code=$dump_gegevens->code&subgroep=$subgroep\">$dump_gegevens->uitvoering</a>"; if ($dump_gegevens->omschrijving <> "*") { echo " $dump_gegevens->omschrijving"; } echo "<br>\n"; } if ($temp[1] == $subgroep) { echo "<a href=\"producten.php?code=$dump_gegevens->code&subgroep=$subgroep\">$dump_gegevens->uitvoering</a>"; if ($dump_gegevens->omschrijving <> "*") { echo " $dump_gegevens->omschrijving"; } echo "<br>\n"; } if ($temp[2] == $subgroep) { echo "<a href=\"producten.php?code=$dump_gegevens->code&subgroep=$subgroep\">$dump_gegevens->uitvoering</a>"; if ($dump_gegevens->omschrijving <> "*") { echo " $dump_gegevens->omschrijving"; } echo "<br>\n"; } if ($temp[3] == $subgroep) { ... } .. etc. if ($temp[7] == $subgroep) { ... } The field $dump_gegevens->subgroep contains data with the following format: *:*:*:*:*:*:*:* where * can be a 4 digit value or a * (default when not used). For example: 1002:1502:1604:*:*:*:*:* Could the problem be the fact that php treats the numbers as numerical values instead of text? Just asking because altering the * values within the complete database is a hell of a job, especially if it's done without use (when the problem lies somewhere else)... Link to comment https://forums.phpfreaks.com/topic/87760-solved-explode-giving-me-undefined-offset-messages/ Share on other sites More sharing options...
GingerRobot Posted January 25, 2008 Share Posted January 25, 2008 Sounds to me like $dump_gegevens->subgroep doesn't always contain the same number of colons, resulting in the generated array containing different numbers of elements. To fix that, and reduce the above bloated code, see: www.php.net/array_search Link to comment https://forums.phpfreaks.com/topic/87760-solved-explode-giving-me-undefined-offset-messages/#findComment-448932 Share on other sites More sharing options...
patrickm Posted January 30, 2008 Author Share Posted January 30, 2008 I solved it differently while ($dump_gegevens = mysql_fetch_object($resultaat)) { $temp = explode (":", $dump_gegevens->subgroep); for ($loop = 0; $loop < count($temp); $loop++){ if ($temp[$loop] == $subgroep) { echo "<a href=\"producten.php?code=$dump_gegevens->code&subgroep=$subgroep\">$dump_gegevens->uitvoering</a>"; if ($dump_gegevens->omschrijving <> "*") { echo " $dump_gegevens->omschrijving"; } echo "<br>\n"; } } } Link to comment https://forums.phpfreaks.com/topic/87760-solved-explode-giving-me-undefined-offset-messages/#findComment-453234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.