Need help, displaying database content not working

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
wolfwood16
Forum Commoner
Posts: 43
Joined: Wed Aug 27, 2008 8:52 am
Contact:

Need help, displaying database content not working

Post by wolfwood16 »

hi all,

im making a program in which a student could view the subject curriculum with his decided curriculum year,...I've created a new table named curr_subjs with the ff fields:

Code: Select all

 
id INT  
subj_code VARCHAR,
subj_desc VARCHAR,
lec_hrs INT,
lab_hrs INT,
subj_units INT,
subj_preq VARCHAR,
subj_sem INT,
subj_level INT
subj_curr VARCHAR
 
now, if the admin created a new curriculum, the name(for example, The New Curriculum) of that curriculum will be stored in curr_names.When he add new subjects, those subjects will be stored in curr_subjs but the value for subj_curr field will be the modified one(thenewcurriculum).

the code is working properly...

but i have a situation which i cant handle regarding on retrieving the data from the table curr_subjs. The code returns no error, but ain't working

on the admin page, there's an option to view the added curriculum, here's the code

Code: Select all

 
include_once 'conn.php';
$getCurriculum = "SELECT * FROM curr_names";
$getCurriculumNow = mysql_query($getCurriculum);
while($crclm = mysql_fetch_array($getCurriculumNow)){
         print<<<HERE
                 <tr>
              <td width="493" height="27" valign="middle" style="background:#ffffff; color:#333333; padding-left: 10px;">$crclm[currname]</td>
          <td width="80" valign="middle" style="background:#ffffff; color:#333333; padding-left: 10px;">$crclm[currcourse]</td>
          <td width="71" valign="middle"><form name="form2" method="post" action="[color=#80FF00]viewcurr.php?mode=View&viewCurrIs=[/color][color=#800000]$crclm[/color][color=#40FF00][id][/color]"><input type="submit" class="qpost_button" name="LetsViewCurr" value="View" /></form></td>
         </tr>
HERE;
 
}
 
Upon selecting his decided curriculum he want to view, the page will bring him to viewcurr.php

Code: Select all

 
//on the top of the page
if(!isset($_SESSION)){
    session_start();
}
 
 
if ($_REQUEST['mode'] == "View") {
    include_once '../admin_/conn.php';
    if ($_GET['id']) {
        $id = (int)$_GET['id'];
        
        $getCurriculumNow = mysql_query("SELECT currname FROM curr_names WHERE id = '$id'");
        
        $strippedCurrName = strtolower(strip_tags(str_replace(' ', '', $getCurriculumNow)));
        echo ($getCurriculumNow." and ".$strippedCurrName) ;
    }
}
 
get the id of the selected curriculum, and returns the unmodified name(The New Curriculum), and modify it with the $strippedCurrName variable so the name now will be (thenewcurriculum).


and on the result section

Code: Select all

 
[color=#800000]$GetSubjsF[/color] = "SELECT * FROM curr_subjs WHERE subj_curr = '$strippedCurrName' AND subj_level = 1 AND subj_desc != '' AND subj_sem = 1";
 
[color=#400000]$GetSubjsNowF[/color] = mysql_query([color=#800000]$GetSubjsF[/color]);
 
while ($subjSecondSemView = mysql_fetch_array($GetSubjsNowS)) {
echo "$subjSecondSemView[subj_code] ";
echo "$subjSecondSemView[subj_desc] ";
echo "$subjSecondSemView[lec_hrs] ";
echo "$subjSecondSemView[lab_hrs] ";
echo "$subjSecondSemView[subj_units] ";
echo "$subjSecondSemView[subj_preq]";
}
 

again, the code did not return any error, but not functioning...

Please help me solve this....Many thanks in advance and God bless us always...
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Need help, displaying database content not working

Post by pcoder »

First of all you make sure your returned query is perfect and try to run it on PHPMYADMIN.
wolfwood16
Forum Commoner
Posts: 43
Joined: Wed Aug 27, 2008 8:52 am
Contact:

Re: Need help, displaying database content not working

Post by wolfwood16 »

when i try running a query to phpmyadmin, it works....i duno, it seems that i'm having problem on getting the id from the fetched array on the view section of admin page...
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Need help, displaying database content not working

Post by pcoder »

Did you try to view your fetched array, I mean like

Code: Select all

 
print_r($subjSecondSemView);
 
wolfwood16
Forum Commoner
Posts: 43
Joined: Wed Aug 27, 2008 8:52 am
Contact:

Re: Need help, displaying database content not working

Post by wolfwood16 »

i run the program and view a curriculum with an id=7 (/admin_/viewcurr.php?mode=View&viewCurrIs=7)

print_r(); did not return anything,

so i assumed it's on the fetched array id of that curriculum so

print_r($getCurriculumNow); returns nothing,
print_r($strippedCurrName); returns nothing,
print_r($GetSubjsNowF); returns "Resource id #4 "
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Need help, displaying database content not working

Post by pcoder »

On your result section note down the line 4 and line 6.
In line 6, i think $GetSubjsNowS should be $GetSubjsNowF.
And then view the array $subjSecondSemView.
wolfwood16
Forum Commoner
Posts: 43
Joined: Wed Aug 27, 2008 8:52 am
Contact:

Re: Need help, displaying database content not working

Post by wolfwood16 »

pcoder wrote:On your result section note down the line 4 and line 6.
In line 6, i think $GetSubjsNowS should be $GetSubjsNowF.
And then view the array $subjSecondSemView.

Sorry bout that but its ok because there's a two results need to be done, first for the First Semester ($GetSubjsNowF) and for the Second Semester ($GetSubjsNowS)

but still the print_r($subjSecondSemView) or print_r($subjFirstSemView) returns nothing...
wolfwood16
Forum Commoner
Posts: 43
Joined: Wed Aug 27, 2008 8:52 am
Contact:

Re: Need help, displaying database content not working

Post by wolfwood16 »

*bump*....anyone?
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Need help, displaying database content not working

Post by pcoder »

Your view Section.

Code: Select all

 
$GetSubjsF = "SELECT * FROM curr_subjs WHERE subj_curr = '$strippedCurrName' AND subj_level = 1 AND subj_desc != '' AND subj_sem = 1"; 
$GetSubjsNowF = mysql_query($GetSubjsF);
while ($subjSecondSemView = mysql_fetch_array($GetSubjsNowS)) {
echo "$subjSecondSemView[subj_code] ";
echo "$subjSecondSemView[subj_desc] ";
echo "$subjSecondSemView[lec_hrs] ";
echo "$subjSecondSemView[lab_hrs] ";
echo "$subjSecondSemView[subj_units] ";
echo "$subjSecondSemView[subj_preq]";
}
 
In this section, the resource is returned in $GetSubjsNowF if Success and you are passing $GetSubjsNowS in mysql_fetch_array. Then how do you get the result?? :)
wolfwood16
Forum Commoner
Posts: 43
Joined: Wed Aug 27, 2008 8:52 am
Contact:

Re: Need help, displaying database content not working

Post by wolfwood16 »

Code: Select all

 
<?php 
        
            $GetSubjsF = "SELECT * FROM curr_subjs WHERE subj_curr = '$strippedCurrName' AND subj_level = 1 AND subj_desc != '' AND subj_sem = 1";
            $GetSubjsNowF = mysql_query($GetSubjsF);
            
            
            
            
            while ($subjFirstSemView = mysql_fetch_array($GetSubjsNowF)) {
                echo "<tr>";
                echo "  <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> $subjFirstSemView[subj_code] </td>";
                echo "  <td width='20%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> $subjFirstSemView[subj_desc] </td>";
                echo "  <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> $subjFirstSemView[lec_hrs] </td>";
                echo "  <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> $subjFirstSemView[lab_hrs] </td>";
                echo "  <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> $subjFirstSemView[subj_units] </td>";
                echo "  <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> $subjFirstSemView[subj_preq] </td>";                
                echo "</tr>";
            }
            
 

still no luck sir...:(
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Need help, displaying database content not working

Post by pcoder »

Try this:

Code: Select all

 
$GetSubjsF = "SELECT * FROM curr_subjs WHERE 1=1";
$GetSubjsNowF = mysql_query($GetSubjsF);
while ($subjSecondSemView = mysql_fetch_array($GetSubjsNowF)) {
//get the content
}
print_r($subjSecondSemView);
 
Does this return any value?? :)
wolfwood16
Forum Commoner
Posts: 43
Joined: Wed Aug 27, 2008 8:52 am
Contact:

Re: Need help, displaying database content not working

Post by wolfwood16 »

still not returning anything sir... :cry: :cry:
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Need help, displaying database content not working

Post by pcoder »

I am assuming your connection is ok.
First of all, try this:

Code: Select all

 
var_dump($GetSubjsNowF);
 
I mean if $GetSubjsNowF returns some resource id and the table curr_subjs is not empty, then this query should return some value.
wolfwood16
Forum Commoner
Posts: 43
Joined: Wed Aug 27, 2008 8:52 am
Contact:

Re: Need help, displaying database content not working

Post by wolfwood16 »

hi sir pcoder, accept my apology for my very late reply. About the program..


var_dump() now return these results

Code: Select all

 
var_dump($GetSubjsNowF)    > resource(4) of type (mysql result) 
var_dump($GetSubjsNowS)    > resource(5) of type (mysql result) 
 
yes my connection is ok, but still no luck sir... :(
Post Reply