Results 1 to 7 of 7

Thread: Get results from a Query, into a hyperlink

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Get results from a Query, into a hyperlink

    I was wondering, when i query my DB, and it kicks out results.
    I wanted first to check and not duplicated any values that are the same.

    So for each of my records, it will have a partnumber,descripton, and a PO attached to it.
    Now alot of my parts will be on the same po, i just wanted it to look through the MBlock_PO column, and only pick out uniq PO numbers, and not display the same PO 4 or 5 times.

    Also how do i make them hyperlinks, that will make the lower portion of my form visable, with update potions of the po..

    i hope this makes sense, or if easier i can make it go to a new page, where it will show all the parts on that po..

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Get results from a Query, into a hyperlink

    you can change your query to something like this:
    PHP Code:
    SELECT DISTINCT partnumberotherfieldotherfield2 FROM tablename WHERE something='something else' 
    This will look for only unique results where instances of partnumber, otherfield, and otherfield2 are not duplicated.

    if you want to make results into links, then just make a link in your while loop..

    PHP Code:
    while($row mysql_fetch_array($blah)){
      echo 
    '<a href="./somepage.php?partnumber=' $row['partnumber'] . '">' $row['sometext'] . '</a><br />\n';

    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Get results from a Query, into a hyperlink

    ok this is what i have but it throws errors.
    Open Purchase Orders:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Inetpub\jf1\php\testing2.php on line 81

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\jf1\php\testing2.php on line 83


    PHP Code:
    <?php  
      $query5 
    "SELECT DISTINCT MBlock_PO From dss "
      
    $result5 = @mysql_query ($query5); 
      
    $count5 mysql_num_rows($result5); //number of results 
      
    while($row mysql_fetch_array($result5MYSQL_ASSOC)){ 
      echo 
    '<a href="./somepage.php?partnumber=' $row['MBlock_PO'] . '">' '</a><br />\n'

    ?>

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Get results from a Query, into a hyperlink

    uhh.. what you have won't even print anything, you have to have text in between your <a> and </a> tags for it to even show up on the page.

    as for the errors, are you connected to a mysql server and did you select the database..? other than that, I have no idea what's wrong with your stuff. the code is fine, so it has to do with your query.

    I just went and made a test table and tried using similar code, which resulted in the same error you were getting.. however, this error was because the table I had was named "table," which is a reserved word, and I was using "SELECT DISTINCT * FROM table." If you use reserved words for field/table names, you should enclose them in (`)'s, so that MySQL will recognize them.

    The code I used is as follows:
    PHP Code:
    <?
      mysql_pconnect(host, user, pass);
      mysql_select_db("testing");
      $request = "SELECT DISTINCT test FROM dss";
      $query = mysql_query($request);
      $num = mysql_num_rows($query);
      echo 'showing ' . $num . ' records<br />';
      $i = 0;
      while($data = mysql_fetch_array($query)){
        $i++;
        echo $i . '. ' . $data['test'] . '<br />';
      }
    ?>
    My final test table was named "dss" with one field named "test" and had 7 entries. All of them were unique, except two, so when using this script it only displayed 5:
    HTML Code:
    showing 5 records
    1. 234
    2. sfsdfs
    3. 452345
    4. 2423
    5. 1
    Not sure how your database is set up, but it seems to me that you're either leaving something important out of the code, or you're using reserved words in your queries and not properly quoting them.
    Like Archer? Check out some Sterling Archer quotes.

  5. #5

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Get results from a Query, into a hyperlink

    thanks for your help kows
    I am trying to search the MBlock_PO in my dss table for PO's that are not duplicated and put them in a list and make them hyperlinks, here is my complete page code.

    When i open the page i get the error below in the block that is holding the php data.


    PHP Code:
    <?php include("DSS_Header.php"); ?>
    <?php 
    require_once ('mysql_connect.php'); ?>
    <?php 

    if(isset($_POST['submitted'])){$errors = array();
    }

    if(empty(
    $_POST['partnumber'])){$errors[] = 'You forgot a part number. ';
    }else{
    $partnumber trim($_POST['partnumber']);
    }

    if(empty(
    $_POST['refnumber'])){$errors[] = 'You forgot a ref number. ';
    }else{
    $refnumber trim($_POST['refnumber']);
    }

    if(empty(
    $_POST['partcomments'])){$errors[] = 'You forgot part comments. ';
    }else{
    $partcomments trim($_POST['partcomments']);
    }

    if(empty(
    $_POST['type'])){$errors[] = 'You forgot part type. ';
    }else{
    $parttype trim($_POST['type']);
    }

    IF (empty(
    $errors)){

    $query "INSERT INTO dss(MBlock_Part_Number,MBlock_Ref,MBlock_Defect,MBlock_Date,MBlock_Type) VALUES ('$partnumber','$refnumber','$partcomments',NOW(),'$parttype')";
    $result = @mysql_query($query);

    if(
    $result){echo 'Information entered into DB';
    //mysql_close();
    }else{echo '<p>'mysql_error(). $query '</p>';
    include(
    "DSS_Footer.php");
    exit(); 
    }}
    ?>

    <?php  
      $query2 
    "SELECT MBlock_Part_Number, MBlock_Ref FROM dss ORDER BY MBlock_Part_Number"
      
    $result2 = @mysql_query ($query2); 
      
    $count mysql_num_rows($result2); //number of results 

      
    if ($count 0){  
       
    // echo "$count"; 
        //while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
          //echo ' <tr><td align="left">' . $row['MBlock_Part_Number'] . '</td><td align="left">' . $row['MBlock_Ref'] . '</td></tr>'; 
        //} 
      
    }else{ 
        echo 
    "No results found for Blocks Pending"
      } 
    ?>

    <?php  
      $query3 
    "SELECT MBlock_Type From dss WHERE MBlock_Type = 'i'"
      
    $result3 = @mysql_query ($query3); 
      
    $count3 mysql_num_rows($result3); //number of results 
    ?>

    <?php  
      $query4 
    "SELECT MBlock_Type From dss WHERE MBlock_Type = 'm'"
      
    $result4 = @mysql_query ($query4); 
      
    $count4 mysql_num_rows($result4); //number of results 
    ?>

    <table cellspacing="2" cellpadding="2" border="0">
    <tr>
        <td><form action="testing2.php" method="post">
    <fieldset><input type ="radio" name="type" value="m" /> Block
    <input type ="radio" name="type" value="i" /> Inverter<br>
    <input type="text" name="partnumber" size="20" maxlenght="20" /><span style="font-size:small;font:sans serif;"> Part Number</span>
    <br><input type="text" name="refnumber" size="20" maxlenght="20" /><span style="font-size:small;font:sans serif;"> Ref #</span>
    </td>
        <td width="300"><fieldset><span style="font-size:small;font:sans serif;">DSS Overview:</span>
    <li><span style="font-size:small;font:sans serif;"><?php echo $count4?> : Massage Blocks Pending</span>
    <li><span style="font-size:small;font:sans serif;"><?php echo $count3?> : Inverters Pending</span>
    <li><span style="font-size:small;font:sans serif;"><?php echo $count?> : Total Items Pending</span>
    </fieldset></td>
        <td width="200"><fieldset>Open Purchase Orders:
    <?  
      require_once ('mysql_connect.php');
      $request5 = "SELECT DISTINCT MBlock_PO FROM dss"; 
      $query5 = mysql_query($request5); 
      $num5 = mysql_num_rows($query5); 
      echo 'showing ' . $num5 . ' records<br />'; 
      $i = 0; 
      while($data = mysql_fetch_array($query5)){ 
        $i++; 
        echo $i . '. ' . $data['MBlock_PO'] . '<br />'; 
      } 
    ?>
        
        </fieldset></td>
    </tr>
    <tr>
        <td><fieldset><span style="font-size:small;font:sans serif;">Part Comments:</span><br> <textarea name="partcomments" rows="6" cols="40">
    </textarea><br><input type="submit" name="submit" value="Enter" align="right"/>
    </fieldset>
    </form></td>
        <td colspan="2" valign="top"><fieldset><a href="testing.php">Test</a> || <a href="testing.php">Test 2 </a> || <a href="testing.php">Test 3</a> || <a href="testing.php">Test 4</a></fieldset></td>
    </tr>
    </table>

    <?php include("DSS_Footer.php"); ?>

  6. #6

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Get results from a Query, into a hyperlink

    ok i think i got it, this is what i used...
    Now how do i make them hyper links?
    i wanted to be able to click on the one of the PO and it goes to another screen where it will list all the items from that po, and i can edit any line on that po.

    PHP Code:
    <?   
      require_once ('mysql_connect.php'); 
      $request5 = "SELECT DISTINCT MBlock_Returned_PO FROM dss";  
      $query5 = mysql_query($request5);  
      $num5 = mysql_num_rows($query5);  
      //echo 'showing ' . $num5 . ' records<br />';  
      $i = 0;  
      while($data = mysql_fetch_array($query5)){  
        //$i++;  
        echo '<li />' . $data['MBlock_Returned_PO'] . '<br />';  
      }  
    ?>

  7. #7

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Get results from a Query, into a hyperlink

    ok just for everyone, here is my php that fixed it

    PHP Code:
    <?   
      require_once ('mysql_connect.php'); 
      $request5 = "SELECT DISTINCT MBlock_Returned_PO,MBlock_PO_Completed FROM dss";  
      $query5 = mysql_query($request5);  
      $num5 = mysql_num_rows($query5);  
      //echo 'showing ' . $num5 . ' records<br />';  
      $i = 0;   
      while($data = mysql_fetch_array($query5)){  
        $i++;  
        echo '<li /> <a href="./somepage.php?partnumber=' . $i . '">' . $data['MBlock_Returned_PO'] . '</a><br />'; 
       // echo '<li />' . $data['MBlock_Returned_PO'] . '<br />';
      }  
    ?>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width