print $str

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nwebhosting
    New Member
    • Oct 2006
    • 23

    #1

    print $str

    Hi. I am very new with php. can you help me with this:
    This code is printing part of the string: image and image_id, but gameandtoyname and pricetype NO. What i am doing wrong? any help?

    <?php
    $sql = "SELECT gameandtoyname, pricetype * FROM dollsimage, dolls where dollsimage.imag e_id=dolls.imag e_id";
    $sql = "SELECT * FROM dollsimage ORDER BY image_date DESC";
    $result = mysql_query ($sql, $conn);
    if (mysql_num_rows ($result)>0) {
    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
    $i++;
    $str .= $i.". ";

    $str .="<img border=\"1\" height=\"90\" width=\"100\" src=\"imagedoll s.php?act=view& iid=".$row["image_id"]." ".$row["gameandtoyname "]." ".$row["pricetype"]." \"></a> ";

    }
    print $str;
    }
    ?>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Only the last query is executed, because you assigned the last SELECT string to the same variable ($sql) as the first SELECT string (also in variable $sql).

    Ronald :cool:

    Comment

    • nwebhosting
      New Member
      • Oct 2006
      • 23

      #3
      Originally posted by ronverdonk
      Only the last query is executed, because you assigned the last SELECT string to the same variable ($sql) as the first SELECT string (also in variable $sql).

      Ronald :cool:
      Hi and thanks.

      If i use 2 differentes variables for SELECT, i will have to use 2 differents variables for the query. How could i use only one for the same condition and print only one string?

      Please help me! it is tricky and i have being using different thing but it give me errors.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Combine the 2 queries into one, selecting columns from both tables in 1 SELECT statement. Such as in this sample:
        Code:
        SELECT fielda, fieldb, fieldc, fieldd 
        FROM table_1, table_2 
        WHERE ......
        Ronald :cool:

        Comment

        • nwebhosting
          New Member
          • Oct 2006
          • 23

          #5
          Originally posted by ronverdonk
          Combine the 2 queries into one, selecting columns from both tables in 1 SELECT statement. Such as in this sample:
          Code:
          SELECT fielda, fieldb, fieldc, fieldd 
          FROM table_1, table_2 
          WHERE ......
          Ronald :cool:
          Trying this way, it give me this error:

          Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in on line 57

          it is because i am missing something in the query?

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Show the code regarding the query and the processing of the results WITHIN [PHP] TAGS!

            Ronald :cool:

            Comment

            • nwebhosting
              New Member
              • Oct 2006
              • 23

              #7
              Originally posted by ronverdonk
              Show the code regarding the query and the processing of the results WITHIN [PHP] TAGS!

              Ronald :cool:
              <?php
              $sql = ("SELECT gameandtoyname, pricetype
              * FROM dollsimage, dolls
              ORDER BY image_date DESC
              where dollsimage.imag e_id= dolls.image_id" );

              $result = mysql_query ($sql, $conn);
              if (mysql_num_rows ($result)>0) {
              while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
              $i++;
              $str .= $i.". ";

              $str .="<img border=\"1\" height=\"90\" width=\"100\" src=\"imagedoll s.php?act=view& iid=".$row["image_id"]."".$row["gameandtoyname "]."".$row["pricetype"]." \"></a> ";

              }
              print $str;
              }
              ?>

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Now I explicitely requested you to put your code between tags!!
                Obviously you refuse to fulfill such a simple request, even though it is in the POSTING GUIDELINES!!

                Therefore I feel no great urge to continue this discussion any further.

                Ronald :cool:

                Comment

                • nwebhosting
                  New Member
                  • Oct 2006
                  • 23

                  #9
                  Originally posted by ronverdonk
                  Now I explicitely requested you to put your code between tags!!
                  Obviously you refuse to fulfill such a simple request, even though it is in the POSTING GUIDELINES!!

                  Therefore I feel no great urge to continue this discussion any further.

                  Ronald :cool:
                  Sorry Sir. I understand the php tags are: <?php ?>
                  sorry again.
                  Still can yuo help Me?....?

                  <?php
                  $sql = ("SELECT gameandtoyname, pricetype
                  * FROM dollsimage, dolls
                  ORDER BY image_date DESC
                  where dollsimage.imag e_id= dolls.image_id" );

                  $result = mysql_query ($sql, $conn);
                  if (mysql_num_rows ($result)>0) {
                  while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
                  $i++;
                  $str .= $i.". ";

                  $str .="<img border=\"1\" height=\"90\" width=\"100\" src=\"imagedoll s.php?act=view& iid=".$row["image_id"]."".$row["gameandtoyname "]."".$row["pricetype"]." \"></a> ";

                  }
                  print $str;
                  }
                  ?>

                  Comment

                  • nwebhosting
                    New Member
                    • Oct 2006
                    • 23

                    #10
                    Sorry now is into tags

                    [PHP]
                    <?php
                    $sql = ("SELECT gameandtoyname, pricetype
                    * FROM dollsimage, dolls
                    ORDER BY image_date DESC
                    where dollsimage.imag e_id= dolls.image_id" );

                    $result = mysql_query ($sql, $conn);
                    if (mysql_num_rows ($result)>0) {
                    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
                    $i++;
                    $str .= $i.". ";

                    $str .="<img border=\"1\" height=\"90\" width=\"100\" src=\"imagedoll s.php?act=view& iid=".$row["image_id"]."".$row["gameandtoyname "]."".$row["pricetype"]." \"></a> ";

                    }
                    print $str;
                    }
                    ?>

                    [/PHP]

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      Ok. Just to make it easier to read, I have assigned the $row values to separate php variables, so it is easier to include in the output string. For the same reason I have also replaced the \"by a simple single slash. That is no criticism, just makes it somewhat easier to read.

                      Now what was wrong was, that you had in your select statement an * without separating comma, so there was an sql error.
                      Also I saw that you forgot to include the field image_date in your select, so I added that. I do not know from which table you want to select image_date, but I assumed from table dollsimage, so you'll have yo change that if not correct.

                      That brings me to the following code snippet for you.[php]<?php
                      $sql = ("SELECT gameandtoyname, pricetype, dollsimage.imag e_id, dollsimage.imag e_date,
                      FROM dollsimage, dolls
                      ORDER BY image_date DESC
                      WHERE dollsimage.imag e_id = dolls.image_id" );

                      $result = mysql_query ($sql, $conn);
                      $str = "";
                      if (mysql_num_rows ($result) > 0) {
                      while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
                      $i++;
                      $image_id = $row["image_id"];
                      $gameandtoyname = $row["gameandtoyname "];
                      $pricetype = $row["pricetype"];
                      $str .="$i. <img border='1' height='90' width='100' src='imagedolls .php?act=view&i id=$image_id$ga meandtoyname$pr icetype'></a> ";
                      print $str;
                      }
                      print $str;
                      }
                      ?>[/php]
                      Let me know if this works (after you checked that the image_date is selected from the correct table).

                      Ronald :cool:

                      Comment

                      • nwebhosting
                        New Member
                        • Oct 2006
                        • 23

                        #12
                        Originally posted by ronverdonk
                        Ok. Just to make it easier to read, I have assigned the $row values to separate php variables, so it is easier to include in the output string. For the same reason I have also replaced the \"by a simple single slash. That is no criticism, just makes it somewhat easier to read.

                        Now what was wrong was, that you had in your select statement an * without separating comma, so there was an sql error.
                        Also I saw that you forgot to include the field image_date in your select, so I added that. I do not know from which table you want to select image_date, but I assumed from table dollsimage, so you'll have yo change that if not correct.

                        That brings me to the following code snippet for you.[php]<?php
                        $sql = ("SELECT gameandtoyname, pricetype, dollsimage.imag e_id, dollsimage.imag e_date,
                        FROM dollsimage, dolls
                        ORDER BY image_date DESC
                        WHERE dollsimage.imag e_id = dolls.image_id" );

                        $result = mysql_query ($sql, $conn);
                        $str = "";
                        if (mysql_num_rows ($result) > 0) {
                        while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
                        $i++;
                        $image_id = $row["image_id"];
                        $gameandtoyname = $row["gameandtoyname "];
                        $pricetype = $row["pricetype"];
                        $str .="$i. <img border='1' height='90' width='100' src='imagedolls .php?act=view&i id=$image_id$ga meandtoyname$pr icetype'></a> ";
                        print $str;
                        }
                        print $str;
                        }
                        ?>[/php]
                        Let me know if this works (after you checked that the image_date is selected from the correct table).

                        Ronald :cool:

                        Sir, still i get this error:
                        Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in C: on line 67
                        Could you please help me with this. Thanx


                        [PHP]
                        <?php
                        $sql = ("SELECT gameandtoyname, pricetype, dollsimage.imag e_id, dollsimage.imag e_date,
                        FROM dollsimage, dolls
                        ORDER BY image_date DESC
                        WHERE dollsimage.imag e_id = dolls.image_id" );

                        $result = mysql_query ($sql, $conn);
                        $str = "";
                        if (mysql_num_rows ($result) > 0) {
                        while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
                        $i++;
                        $image_id = $row["image_id"];
                        $gameandtoyname = $row["gameandtoyname "];
                        $pricetype = $row["pricetype"];
                        $str .="$i. <img border='1' height='90' width='100' src='imagedolls .php?act=view&i id=$image_id$ga meandtoyname$pr icetype'></a> ";
                        print $str;
                        }
                        print $str;
                        }



                        ?>

                        [/PHP]

                        Comment

                        • ronverdonk
                          Recognized Expert Specialist
                          • Jul 2006
                          • 4259

                          #13
                          Of course that code does not work, Before it you'll have to connect to your server and your database. Such as:

                          [php]
                          $con = mysql_connect(" xx", "yy", "zz")
                          or die("Connect error: " . mysql_error());
                          mysql_select_db ("dd")
                          or die("Db select error: " . mysql_error());
                          [/php]
                          Don't forget to change the xx, yy, zz and dd to the actual values!

                          After that you put the select code.

                          Ronald :cool:

                          Comment

                          • nwebhosting
                            New Member
                            • Oct 2006
                            • 23

                            #14
                            Originally posted by ronverdonk
                            Of course that code does not work, Before it you'll have to connect to your server and your database. Such as:

                            [php]
                            $con = mysql_connect(" xx", "yy", "zz")
                            or die("Connect error: " . mysql_error());
                            mysql_select_db ("dd")
                            or die("Db select error: " . mysql_error());
                            [/php]
                            Don't forget to change the xx, yy, zz and dd to the actual values!

                            After that you put the select code.

                            Ronald :cool:


                            Sir: I do have the connection. here is the rest of the code:
                            thankx alot.

                            [PHP]
                            <?php


                            // database connection
                            $conn = mysql_connect(" localhost", "root") OR DIE (mysql_error()) ;
                            @mysql_select_d b ("products", $conn) OR DIE (mysql_error()) ;

                            // browse the file and click the submit button
                            if ($_FILES) {
                            $image_types = Array ("image/bmp",
                            "image/jpeg",
                            "image/pjpeg",
                            "image/gif",
                            "image/x-png");

                            $userfile = addslashes (fread (fopen ($_FILES["userfile"]["tmp_name"], "r"), filesize ($_FILES["userfile"]["tmp_name"])));
                            $file_name = $_FILES["userfile"]["name"];
                            $file_size = $_FILES["userfile"]["size"];
                            $file_type = $_FILES["userfile"]["type"];

                            if (in_array (strtolower ($file_type), $image_types)) {
                            $sql = "INSERT INTO dollsimage (image_type, image, image_size, image_name, image_date) ";
                            $sql.= "VALUES (";
                            $sql.= "'{$file_type}' , '{$userfile}', '{$file_size}', '{$file_name}', NOW())";
                            @mysql_query ($sql, $conn);
                            Header("Locatio n:".$_SERVER["PHP_SELF"]);
                            exit();
                            }
                            }

                            // view or remove
                            if ($_GET) {
                            $iid = $_GET["iid"];
                            $act = $_GET["act"];
                            switch ($act) {
                            case rem:
                            $sql = "DELETE FROM dollsimage WHERE image_id=$iid";
                            @mysql_query ($sql, $conn);
                            Header("Locatio n:./textimage4.php" );
                            exit();
                            break;
                            default:
                            print "<img src=\"imagedoll s.php?iid=$iid\ ">";
                            break;
                            }
                            }

                            ?>

                            <form method="post" enctype="multip art/form-data">
                            Select Image File: <input type="file" name="userfile" size="40"><inpu t type="submit" value="submit">
                            </form>
                            <?php
                            $sql = ("SELECT gameandtoyname, pricetype, dollsimage.imag e_id, dollsimage.imag e_date,
                            FROM dollsimage, dolls
                            ORDER BY image_date DESC
                            WHERE dollsimage.imag e_id = dolls.image_id" );

                            $result = mysql_query ($sql, $conn);
                            $str = "";
                            if (mysql_num_rows ($result) > 0) {
                            while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
                            $i++;
                            $image_id = $row["image_id"];
                            $gameandtoyname = $row["gameandtoyname "];
                            $pricetype = $row["pricetype"];
                            $str .="$i. <img border='1' height='90' width='100' src='imagedolls .php?act=view&i id=$image_id$ga meandtoyname$pr icetype'></a> ";
                            print $str;
                            }
                            print $str;
                            }



                            ?>
                            [/PHP]



                            Imagedolls.php :

                            [PHP]
                            <?php


                            // database connection
                            $conn = mysql_connect(" localhost", "root") OR DIE (mysql_error()) ;
                            @mysql_select_d b ("products", $conn) OR DIE (mysql_error()) ;
                            $sql = "SELECT * FROM dollsimage WHERE image_id=".$_GE T["iid"];
                            $result = mysql_query ($sql, $conn);
                            if (mysql_num_rows ($result)>0) {
                            $row = @mysql_fetch_ar ray ($result);
                            $image_type = $row["image_type "];
                            $image = $row["image"];
                            Header ("Content-type: $image_type");
                            print $image;
                            }
                            ?>
                            [/PHP]

                            Comment

                            • ronverdonk
                              Recognized Expert Specialist
                              • Jul 2006
                              • 4259

                              #15
                              I cannot see the error, but it is late, so I could overlook it. You could add the following line after the query to see if it returns an error message:
                              [php]if (!$result) {
                              die('Invalid query: ' . mysql_error());
                              }[/php]
                              Ronald :cool:

                              Comment

                              Working...