php, postgresql view.

Hi

Can someone help me with this problem:

I at today's date when I add a game in a sql-database, I want to give games that are new'er than 10 days a image (new).
I use this code to view the sql-database:

$num = pg_NumRows($result);
$i = 0;
$test = 1;
while ($i < $num) {
while ($test > 20) {
echo  "<TR><TD COLSPAN=3><CENTER>";
                  include("menu.php3");
echo "</CENTER></TD></TR>";
$test = 1;
}
echo  "<TD><TD>";
echo pg_Result(
while ($date, $i > $today-10)) {
echo  "<IMG SRC=../../images/flag_new.gif>");
}                  
echo  "<TD><TD>";
echo pg_Result($result, $i,  "name");
echo  "</TD><TD><CENTER>";
echo pg_Result($result, $i,  "cd");
echo  "</CENTER></TD><TD>";
echo pg_Result($result, $i,  "typegamename");
echo  "</TD></TR>";
$test++;                
$i++;
}

This does't work, do anyone have a solution for this problem??

SvennYKro
svennykroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

svennykroAuthor Commented:
$today = date("j.m.Y");

This is the $today
0
jasmoft146Commented:
What error is it giving?
0
svennykroAuthor Commented:
$num = pg_NumRows($result);
$i = 0;
$test = 1;
while ($i < $num) {
while ($test > 20) {
echo  "<TR><TD COLSPAN=3><CENTER>";
include("menu.php3");
echo "</CENTER></TD></TR>";
$test = 1;
}
echo  "<TR><TD>"; 
echo pg_Result(
while ($date, $i > $today-10)) {
echo  "<IMG SRC=../../images/flag_new.gif>");
}
echo  "<TD><TD>";
echo pg_Result($result, $i,  "name");
echo  "</TD><TD><CENTER>";
echo pg_Result($result, $i,  "cd");
echo  "</CENTER></TD><TD>";
echo pg_Result($result, $i,  "typegamename");
echo  "</TD></TR>";
$test++;                
$i++;
}

$today = date("j.m.y");

Some changes!
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

svennykroAuthor Commented:
$today = date("j/m/y");

Changed  "j.m.y" to "j/m/y"
0
jasmoft146Commented:
Also not all of your code printed correctly.
0
svennykroAuthor Commented:
$today = date("j/m/y");

Changed  "j.m.y" to "j/m/y"
0
svennykroAuthor Commented:
This part I want to use to print the
"new"-image to games that is less than 10 says since I added them to the sql-database (postgresql)

I think that

echo pg_Result(
while ($date, $i > $today-10)) {
echo  "<IMG SRC=../../images/flag_new.gif>");
}

Is not printet correctly.
0
svennykroAuthor Commented:
This part I want to use to print the
"new"-image to games that is less than 10 says since I added them to the sql-database (postgresql)

I think that

echo pg_Result(
while ($date, $i > $today-10)) {
echo  "<IMG SRC=../../images/flag_new.gif>");
}

Is not printet correctly.
0
svennykroAuthor Commented:
Error message:
<b>Parse error</b>:  parse error, expecting `')'' in <b>/home/u-kro/public_html/CD_database/develop/view.php3</b> on line <b>58</b><br>
0
svennykroAuthor Commented:
while ($date, $i > $today-10)) {

IS LINE 58
0
svennykroAuthor Commented:
while ($date, $i > $today-10)) {

IS LINE 58
0
jasmoft146Commented:
Here's my first crack at it:

$num = pg_NumRows($result);
$i = 0;
$test = 1;
while ($i < $num) {
while ($test > 20) {
echo  "<TR><TD COLSPAN=3><CENTER>";
include("menu.php3");
echo "</CENTER></TD></TR>";
$test = 1;
}
echo  "<TR><TD>"; 
echo pg_Result($result, $i,  "date");

for ($j = 1; $j <= 10; $j++) {
    $date2 = date("j/m/y", mktime(0,0,0,date("m")  ,date("d") ,date("Y"))-$j);
    if (pg_Result($result, $i,  "date") = $date2 ){
echo  "<IMG SRC=../../images/flag_new.gif>");
}
}

echo  "<TD><TD>";
echo pg_Result($result, $i,  "name");
echo  "</TD><TD><CENTER>";
echo pg_Result($result, $i,  "cd");
echo  "</CENTER></TD><TD>";
echo pg_Result($result, $i,  "typegamename");
echo  "</TD></TR>";
$test++;                  
$i++;
}
0
jasmoft146Commented:
See, you gave the while two arguements, and it couldn't handle that.
0
svennykroAuthor Commented:
error message

<b>Warning</b>:  Unexpected character in input:  '' (ASCII=31) state=1 in <b>/home/u-kro/public_html/CD_database/develop/view.php3</b> on line <b>56</b><br>
<br>
<b>Parse error</b>:  parse error in <b>/home/u-kro/public_html/CD_database/develop/view.php3</b> on line <b>60</b><br>


in my sql-database I use date-format: 2/4/00
0
svennykroAuthor Commented:
I fixed the warning-message, but i still have the parse error-message!
0
jasmoft146Commented:
$num = pg_NumRows($result);
$i = 0;
$test = 1;
while ($i < $num) {
while ($test > 20) {
echo  "<TR><TD COLSPAN=3><CENTER>";
include("menu.php3");
echo "</CENTER></TD></TR>";
$test = 1;
}
echo  "<TR><TD>";
echo pg_Result($result, $i,  "date");

for ($j = 1; $j <= 10; $j++) {
    $date2 = date("j/m/y", mktime(0,0,0,date("m")  ,date("d")-$j ,date("Y")));
    if (pg_Result($result, $i,  "date") == $date2 ){
echo  "<IMG SRC=../../images/flag_new.gif>");
}
}

echo  "<TD><TD>";
echo pg_Result($result, $i,  "name");
echo  "</TD><TD><CENTER>";
echo pg_Result($result, $i,  "cd");
echo  "</CENTER></TD><TD>";
echo pg_Result($result, $i,  "typegamename");
echo  "</TD></TR>";
$test++;                  
$i++;
}

0
svennykroAuthor Commented:
<HTML>
<HEAD>
<TITLE>CD-database: GaMeZ: Show</TITLE>
</HEAD>
<BODY>
<?PHP
      require("menu.php3");
?>
<img src="../../images/games_flame.jpg">
<DIV ALIGN="center">
<?
$today = date("j/m/y");
PRINT "Dato: $today";
?>
<TABLE BORDER="0">
<TR>
<TH></TH>
<TH WIDTH=250 HEIGHT=50><a href="view.php3">Tittel<img src="../../images/sortdown.gif" border="0"></a></TH>
<TH WIDTH=150><a href="viewcd.php3">Antall cd'er</a></TH>

<TH><a href="viewtype.php3">Type spill</a></TH>
</TR>

<?PHP

        $conn = pg_Connect( "144.84.196.243",  "5432",  "",  "",  "cddb");

        if (!$conn) {

                echo  "An error occurred.\n";
                exit;
        }

        $result = pg_Exec($conn,
                 "SELECT games.date, games.name, games.cd, typegames.typegamename
                        FROM apps, typeapps
                        WHERE games.typegameid = typegames.typegameid
                        ORDER BY name;");

        if (!$result) {

                echo  "An error occurred.\n";
                exit;
        }

$num = pg_NumRows($result);
$i = 0;
$test = 1;
while ($i < $num) {
      while ($test > 20) {
              echo  "<TR><TD COLSPAN=3><CENTER>";
                include("menu.php3");
                echo "</CENTER></TD></TR>";
                $test = 1;
                }
                echo  "<TR><TD>";
                echo pg_Result($result, $i,  "date");
            for ($j = 1; $j <= 10; $j++) {
                      $date2 = date("j/m/y", mktime(0,0,0,date("m")  ,date("d") ,date("y"))-$j);
                      if (pg_Result($result, $i,  "date") = $date2 ) {
                            echo  "<IMG SRC=../../images/flag_new.gif>");
                }
            }

                echo  "<TD><TD>";
                echo pg_Result($result, $i,  "name");
                echo  "</TD><TD><CENTER>";
                echo pg_Result($result, $i,  "cd");
                echo  "</CENTER></TD><TD>";
                echo pg_Result($result, $i,  "typegamename");
                echo  "</TD></TR>";
                $test++;                  
                $i++;
}

        pg_FreeResult($result);
        pg_Close($conn);
echo  "Antall: ", $num;
?>

</TABLE>
<?
      include("menu.php3");
?>
</BODY>
</HTML>
0
jasmoft146Commented:
Sorry, I used vb this morning and forgot the == instead of = is used in php.
0
svennykroAuthor Commented:
for ($j == 1; $j <= 10; $j++) {

Like this??
0
svennykroAuthor Commented:
if (pg_Result($result, $i,  "date") == $date2 ) {

or this??
0
svennykroAuthor Commented:
I changed:
echo  "<IMG SRC=../../images/flag_new.gif>");
to
echo  "<IMG SRC=../../images/flag_new.gif>";

and I get don't get any error, but I don't get any image!
0
jasmoft146Commented:
for ($j = 1; $j <= 10; $j++) {
    $date2 = date("j/m/y", mktime(0,0,0,date("m")  ,date("d")-$j ,date("Y")));
    if (pg_Result($result, $i,  "date") == $date2 ){
echo  "<IMG SRC=../../images/flag_new.gif>";
}
}


Also you database must have text that matches the date result
eg.
31/01/00
and
2/02/00
0
svennykroAuthor Commented:
I get the date on the screen, but not the image...
0
svennykroAuthor Commented:
The database outputs the date: 04-02-2000 I have changed the script:
<HTML>
<HEAD>
<TITLE>CD-database: GaMeZ: Show</TITLE>
</HEAD>
<BODY>
<?PHP
      require("menu.php3");
?>
<img src="../../images/games_flame.jpg">
<DIV ALIGN="center">
<?
$today = date("d-m-Y");
PRINT "Dato: $today";
?>
<TABLE BORDER="1">
<TR>
<TH>image</TH>
<TH WIDTH=250 HEIGHT=50><a href="view.php3">Tittel<img src="../../images/sortdown.gif" border="0"></a></TH>
<TH WIDTH=150><a href="viewcd.php3">Antall cd'er</a></TH>

<TH><a href="viewtype.php3">Type spill</a></TH>
</TR>

<?PHP

        $conn = pg_Connect( "144.84.196.243",  "5432",  "",  "",  "cddb");

        if (!$conn) {

                echo  "An error occurred.\n";
                exit;
        }

        $result = pg_Exec($conn,
                 "SELECT games.date, games.name, games.cd, typegames.typegamename
                        FROM apps, typeapps
                        WHERE games.typegameid = typegames.typegameid
                        ORDER BY name;");

        if (!$result) {

                echo  "An error occurred.\n";
                exit;
        }

$num = pg_NumRows($result);
$i = 0;
$test = 1;
while ($i < $num) {
      while ($test > 20) {
              echo  "<TR><TD COLSPAN=3><CENTER>";
                include("menu.php3");
                echo "</CENTER></TD></TR>";
                $test = 1;
                }
                echo  "<TR><TD>";
                echo pg_Result($result, $i,  "date");
            for ($j = 1; $j <= 10; $j++) {
                        $date2 = date("j-m-Y", mktime(0,0,0,date("m")  ,date("d")-$j ,date("Y")));
                      if (pg_Result($result, $i,  "date") == $date2 ){
                          echo  "<IMG SRC=../../images/flag_new.gif>";
                    }
                 }       


                echo  "<TD><TD>";
                echo pg_Result($result, $i,  "name");
                echo  "</TD><TD><CENTER>";
                echo pg_Result($result, $i,  "cd");
                echo  "</CENTER></TD><TD>";
                echo pg_Result($result, $i,  "typegamename");
                echo  "</TD></TR>";
                $test++;                  
                $i++;
}

        pg_FreeResult($result);
        pg_Close($conn);
echo  "Antall: ", $num;
?>

</TABLE>
<?
      include("menu.php3");
?>
</BODY>
</HTML>


This script output the date but no image on new games
0
svennykroAuthor Commented:
The database outputs the date: 04-02-2000 I have changed the script:
<HTML>
<HEAD>
<TITLE>CD-database: GaMeZ: Show</TITLE>
</HEAD>
<BODY>
<?PHP
      require("menu.php3");
?>
<img src="../../images/games_flame.jpg">
<DIV ALIGN="center">
<?
$today = date("d-m-Y");
PRINT "Dato: $today";
?>
<TABLE BORDER="1">
<TR>
<TH>image</TH>
<TH WIDTH=250 HEIGHT=50><a href="view.php3">Tittel<img src="../../images/sortdown.gif" border="0"></a></TH>
<TH WIDTH=150><a href="viewcd.php3">Antall cd'er</a></TH>

<TH><a href="viewtype.php3">Type spill</a></TH>
</TR>

<?PHP

        $conn = pg_Connect( "144.84.196.243",  "5432",  "",  "",  "cddb");

        if (!$conn) {

                echo  "An error occurred.\n";
                exit;
        }

        $result = pg_Exec($conn,
                 "SELECT games.date, games.name, games.cd, typegames.typegamename
                        FROM apps, typeapps
                        WHERE games.typegameid = typegames.typegameid
                        ORDER BY name;");

        if (!$result) {

                echo  "An error occurred.\n";
                exit;
        }

$num = pg_NumRows($result);
$i = 0;
$test = 1;
while ($i < $num) {
      while ($test > 20) {
              echo  "<TR><TD COLSPAN=3><CENTER>";
                include("menu.php3");
                echo "</CENTER></TD></TR>";
                $test = 1;
                }
                echo  "<TR><TD>";
                echo pg_Result($result, $i,  "date");
            for ($j = 1; $j <= 10; $j++) {
                        $date2 = date("j-m-Y", mktime(0,0,0,date("m")  ,date("d")-$j ,date("Y")));
                      if (pg_Result($result, $i,  "date") == $date2 ){
                          echo  "<IMG SRC=../../images/flag_new.gif>";
                    }
                 }       


                echo  "<TD><TD>";
                echo pg_Result($result, $i,  "name");
                echo  "</TD><TD><CENTER>";
                echo pg_Result($result, $i,  "cd");
                echo  "</CENTER></TD><TD>";
                echo pg_Result($result, $i,  "typegamename");
                echo  "</TD></TR>";
                $test++;                  
                $i++;
}

        pg_FreeResult($result);
        pg_Close($conn);
echo  "Antall: ", $num;
?>

</TABLE>
<?
      include("menu.php3");
?>
</BODY>
</HTML>


This script output the date but no image on new games
0
jasmoft146Commented:
echo date2 and visually check that the dates are exactly the same.  Be back in 1 hour.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
svennykroAuthor Commented:
I have worked with it now, and the 200 points are yours!!!

Thanks!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.