Jump to content

Archived

This topic is now archived and is closed to further replies.

kalivos

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
[code]$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']);
}[/code]

I then display the arrays with a loop.

Share this post


Link to post
Share on other sites
What if you change your query a bit to look like this:

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

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?
[code]
<?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 />";
}
?>
[/code]

Share this post


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

Share this post


Link to post
Share on other sites

×

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.