Jump to content

$result is cutting off results


Clinton

Recommended Posts

When it parses it's not pulling everything through.

 

$datecode displays right but $producttype and $productdescripton get cut off.

 

I.E., set as VARCHAR in db, $producttype in database reads 'MS NONEL' but is only parsing 'MS'. $productdescription in db reads '20 feet long' but is only parsing the '20'.

 

Any ideas on why this is happening?

 


$result = mysql_query("SELECT * FROM masterlist ORDER BY datecode");

if ($choice=="")
{
echo "<form action='' method='post'>";

echo "<select name='choice' value=''></option>";

while($nt=mysql_fetch_array($result))
{

echo "<option value=$nt[datecode]>$nt[datecode]</option>";
echo "<INPUT type=text name=type value=$nt[producttype]>";
echo "<INPUT type=text name=type value=$nt[productdescription]>";
}

echo "</select>";

echo "<input type='submit' value='Select'>";
}

else
echo "You have selected $choice$type. Have a nice day!";
?>

Link to comment
Share on other sites

All HTML values must be enclosed in " ", and keys for arrays should be enclosed in ' ' (unless parsing a variable key).  Fix those and it'll work (the HTML thing is the real problem though, the second one is just good practice).

Link to comment
Share on other sites

Thank you, that did work.

 

Now how about this...

 

... one of the echo statements below is not... echoing. How did I go wrong there?

 


<?php
if ($choice=="")
{
echo "<form action='' method='post'>";

echo "<select name='choice' value=''>Date Code</option>";

echo "Select the appropriate date code to view/edit: ";   ///////////////////<<<<<<<<------------- This one right here

while($nt=mysql_fetch_array($result))
{

echo "<option value=$nt[datecode]>$nt[datecode]</option>";
echo "<INPUT type=text name=type value='$nt[producttype]'>";
echo "<INPUT type=text name=type value='$nt[productdescription]'>";
}

echo "</select>";

echo "<input type='submit' value='Select'>";
}

else
echo "You have selected $choice$type. Have a nice day!";
?>

Link to comment
Share on other sites

it echo'd just fine for me.

cleaned it up some:

<?php
if ($choice=="")
{
echo "<form action='' method='post'>\n";

echo "<select name='choice' value=''>Date Code</option>\n";

echo "Select the appropriate date code to view/edit: \n";   ///////////////////<<<<<<<<------------- This one right here

while($nt=mysql_fetch_array($result))
{

echo "<option value='{$nt['datecode']}'>{$nt['datecode']}</option>\n";
echo "<INPUT type=text name=type value='{$nt['producttype']}'>\n";
echo "<INPUT type=text name=type value='{$nt['productdescription']}'>\n";
}

echo "</select>\n";

echo "<input type='submit' value='Select'>\n";
}

else
echo "You have selected $choice$type. Have a nice day!";
?>

Link to comment
Share on other sites

\n is a linebreak... makes things prettier when you view the source

 

Your problem is you aren't following HTML rules.

 

<select> elements should only have <option> elements in them, and should be closed with a </select> before any other elements are created.

 

Rules broken

echo "<select name='choice' value=''>Date Code</option>\n";

echo "Select the appropriate date code to view/edit: \n";   ///////////////////<<<<<<<<------------- This one right here

 

echo "<option value='{$nt['datecode']}'>{$nt['datecode']}</option>\n";
echo "<INPUT type=text name=type value='{$nt['producttype']}'>\n";
echo "<INPUT type=text name=type value='{$nt['productdescription']}'>\n";

 

I think you need to check this out

http://www.w3schools.com/HTML/

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.