Trouble in dispalying a recordset plus an output.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
su93rn0va
Forum Newbie
Posts: 5
Joined: Thu Apr 10, 2008 8:10 am

Trouble in dispalying a recordset plus an output.

Post by su93rn0va »

Everah | Please use the correct bbCode tags when posting code in the forums. You can use [code], [php], [{lang}] or [syntax="{lang}"] where {lang} is the lowercase string name of the language you want to parse.

hi guys thx for reading this! Ok here is the deal, I am building an admin panel and i have written a recordset so to display some fields from my database. This would be my list so i can delete or update an entry from my database. This is my code:

Code: Select all

<body>
<?php echo '<p><left><a href="insert_record.php">Add a new record</a></left></p>';
include "/usr/home/mysite.com/htdocs/inc/dbconn.php";
$q = "select codeno, brief, type, resort from estateinfo";
if ($sortby){
    $q=$q." order by $sortby";
    }
    $result = mysql_query($q);
    $num_rows=mysql_num_rows($result);
    echo '<center>';
    echo "<h1> REAL ESTATE</h1></br>";
    echo "<h2>ESTATE LIST</h2>";
    echo "</center>";
    echo "<table border=\"0\" cellpadding=\"5\" align=\"center\">";
    echo '<tr>';
    echo "<td><a href=edit.php?sortby=codeno>ID</a></td>";
    echo "<td><a href=edit.php?sortby=type>CATEGORY</a></td>";
    echo "<td><a href=edit.php?sortby=resort>LOCATION</a></td>";
    echo "<td>BRIEF</td>";
    echo '</tr>';
    
    while ($row= mysql_fetch_array($result,MYSQL_BOTH))
    {
        echo '<tr>';
        $codeno=$row['codeno'];
        [color=#0000FF]include('inc/uploadform.php');[/color]
        $type=$row['type'];
        $resort=$row['resort'];
        $brief=$row['brief'];
        echo "<td>$codeno</td>";
        echo "<td>$type</td>";
        echo "<td>$resort</td>";
        if (strlen($brief)>strlen(substr($brief,0,50))){
        echo '<td>'.substr($brief,0,50).'...</td>';
        }
        else {echo "<td>$brief</td>";}
        echo "<td><a href = update_estate.php?id=$codeno>Edit</a></td>";
        echo "<td><a href = delete_estate.php?id=$codeno>Delete</a></td>";
        echo "</tr>";
        echo '<tr>';
        echo '<td colspan=\"6\">';
        echo "$output";
        echo '</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td colspan=\"6\">';
        echo '<br />';
        echo '</td>';
        echo '</tr>';
            }
    echo "</table>";
    echo "<center>";
    echo '<a href="insert_record.php">Add a new record</a>'.'  |  '.'<a href="list.php">refresh</a>';
    echo "</center>";
?>
</body>
As you can see i Include a file called uploadform.php which is going to help to upload images.. this is the code:

Code: Select all

<?php 
$output .= "
<table width=\"100%\" cellpadding='0' cellspacing='0'>
 <tr><td><form enctype=\"multipart/form-data\" action=\"../[color=#FF0000]uploader.php?id=$codeno[/color]\" method=\"POST\">";
 
$maxsize = ini_get('upload_max_filesize');
if (!is_numeric($maxsize)) 
        {
   if (strpos($maxsize, 'M') !== false)
       $maxsize = intval($maxsize)*1024*1024;
   elseif (strpos($maxsize, 'K') !== false)
       $maxsize = intval($maxsize)*1024;
   elseif (strpos($maxsize, 'G') !== false)
       $maxsize = intval($maxsize)*1024*1024*1024;
        }
                $output .=  '<input type="hidden" name="MAX_FILE_SIZE" value="' . $maxsize.'\" />';
 
                $output .= "
Choose an image : 
<input name=\"uploadedfile\" type=\"file\" class=\"Button\" /> 
<input type=\"submit\" class=\"Button\" value=\"Upload File\" />
<input type=\"hidden\" name=\"codeno\" value=\"$codeno\" />
</form></td></tr></table>
                ";
?>
As you already understand the $output var in first script comes from the uploadform.php!
HERE IS THE PROBLEM I NEED TO SOLVE How can I get the $codeno var of all my records seperatly in uploadform action without displaying the $output more than one time.(this is what happens when i put the include inside the while loop).Guys I would be grateful to you if you could help me out!



Everah | Please use the correct bbCode tags when posting code in the forums. You can use [code], [php], [{lang}] or [syntax="{lang}"] where {lang} is the lowercase string name of the language you want to parse.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Trouble in dispalying a recordset plus an output.

Post by Jade »

Please use the code tags when posting code!! Thanks :)

As far as your question goes, you're concatenating the stuff from the form with:

Code: Select all

$output .= "
Choose an image :
<input name=\"uploadedfile\" type=\"file\" class=\"Button\" />
<input type=\"submit\" class=\"Button\" value=\"Upload File\" />
<input type=\"hidden\" name=\"codeno\" value=\"$codeno\" />
</form></td></tr></table>
";
If you don't want it to add that on again and again every time the loop runs you need to remove the concatenation like this:

Code: Select all

$output = "
Choose an image :
<input name=\"uploadedfile\" type=\"file\" class=\"Button\" />
<input type=\"submit\" class=\"Button\" value=\"Upload File\" />
<input type=\"hidden\" name=\"codeno\" value=\"$codeno\" />
</form></td></tr></table>
";
That way it won't be repeated every time it goes through the loop.
su93rn0va
Forum Newbie
Posts: 5
Joined: Thu Apr 10, 2008 8:10 am

Re: Trouble in dispalying a recordset plus an output.

Post by su93rn0va »

Jade wrote:Please use the code tags when posting code!! Thanks :)

As far as your question goes, you're concatenating the stuff from the form with:

Code: Select all

$output .= "
Choose an image :
<input name=\"uploadedfile\" type=\"file\" class=\"Button\" />
<input type=\"submit\" class=\"Button\" value=\"Upload File\" />
<input type=\"hidden\" name=\"codeno\" value=\"$codeno\" />
</form></td></tr></table>
";
If you don't want it to add that on again and again every time the loop runs you need to remove the concatenation like this:

Code: Select all

$output = "
Choose an image :
<input name=\"uploadedfile\" type=\"file\" class=\"Button\" />
<input type=\"submit\" class=\"Button\" value=\"Upload File\" />
<input type=\"hidden\" name=\"codeno\" value=\"$codeno\" />
</form></td></tr></table>
";
That way it won't be repeated every time it goes through the loop.
Jade I need to say thanks for the quick response! As for the code tags :banghead: I am going to use them from now on as it was my first time i posted on a forum. You certainly do a good job! Your quote was abjolutely right and helped me a lot. Cheers :lol:
Post Reply