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?
Link to comment
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.
Link to comment
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]
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.