Jump to content

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


kalivos

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?
[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.
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]

Archived

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

×
×
  • 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.