Jump to content

query returns nothing


esandra

Recommended Posts

this is supposed to display the distinct first two characters of a string(billnmbr) in a combobox

ive tried this on phpmyadmin and it returns 08..

which is correct

when i run this on my server, it returns nothing..

there must be something wrong with the way i called the billnmbr

does anybody have an idea on how i could call and display this correctly?

thanks and have a nice day.

<?php
  $mquery = "select distinct(substring(`billnmbr`, 1, 2)) from `tbltest`";
  $mres =mysql_query($mquery) or die(mysql_error());
  	while($mrow=mysql_fetch_array($mres)){
	$mm = $mrow['billnmbr'];
	 echo "<option value=" . $mrow['billnmbr'] . ">";
	 echo $mrow['billnmbr'] . "</option>"; 	
	} 
echo " </select>";
  ?>

Link to comment
https://forums.phpfreaks.com/topic/213866-query-returns-nothing/
Share on other sites

I think theres an unassigned variable.

 

$mm = $mrow['billnmbr'];
echo "<option value=" . $mrow['billnmbr'] . ">";

 

what is $mm ?

 

You cant assign a variable to an unassigned variable because it would be zero... hence it not showing anything.

Change the query to

 

  $mquery = "select distinct(substring(`billnmbr`, 1, 2)) AS billnmbr from `tbltest`";

 

What's happening is the field is being returned but it wasn't called bullnmbr, it was called substring(`billnmbr`, 1, 2)

 

Use the AS syntax to give that a friendly name.

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.