Jump to content


Photo

"-" in data conflicts with SELECT query *solved*


  • Please log in to reply
4 replies to this topic

#1 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 09 August 2006 - 07:16 PM

I have a column in my database named "alt" defined as "text". When I perform a SELECT query from that row, it pulls until a "-" is found. It displays random segments from that pull.

Example data in db: ...through the Sierra Nevada Mountains-what happened at this year's race?

Data displayed:what happened at this year's race?

I know that ' or " can cause wierd things like this to happen, but - ? Anyone seen this before?
Make a donation to phpfreaks. They need your help![br][br]

#2 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 09 August 2006 - 07:17 PM

What does your query look like?

#3 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 09 August 2006 - 07:22 PM

$conn->query("SELECT * FROM ads WHERE type='$type' AND start < '$start_date' AND (end > '$end_date' OR end = '')");

		while($my_row=$conn->get_row()){	
			$this->id[] = stripslashes($my_row['ID']);
			$this->link[] = stripslashes($my_row['out_id']);
			$this->alt[] = stripslashes($my_row['alt']);
			$this->img[] = stripslashes($my_row['img']);
			$this->title[] = stripslashes($my_row['title']);
		}

I then display the arrays with a loop.
Make a donation to phpfreaks. They need your help![br][br]

#4 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 09 August 2006 - 08:03 PM

What if you change your query a bit to look like this:

SELECT * FROM ads WHERE type = '{$type}' AND start < '{$start_date}' AND (end > '{$end_date}
 OR end = '')

Adding in the curly braces around the varibles. SQL might be seeing the - as a minus operator in the query.  Which doesn't make sense to me while I type this out but worth a shot.

What if you just try to output the info without putting into your class?
<?php
$qry = "SELECT * Blahblahblah WHERE blah = blah";
$query = mysql_query($qry) or die("Error: ". mysql_error());

while($my_row = mysql_fetch_array($query, MYSQL_ASSOC)) {
  echo "{$my_row['ID']} <br />
          {$my_row['out_id']}<br />
          {$my_row['alt']}</br />
          {$my_row['img']}<br />
          {$my_row['title']}<br />";
}
?>


#5 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 09 August 2006 - 08:29 PM

After outputing the data and realizing that it WAS working correctly, I looked at the rest of my code. I was useing "-" as a seperator and thus exploding() to find my data :-/

Thanks for the help
Make a donation to phpfreaks. They need your help![br][br]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users