Jump to content

[SOLVED] "explode" giving me "undefined offset" messages


patrickm

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.