Menu

Changing Display type

Help
InTIM
2007-03-18
2013-06-03
  • InTIM

    InTIM - 2007-03-18

    I would like to change the way the file upload displays back to the site from the database.  I would like to make the uploaded file report back as a download link when they upload a file.  Instead it shows the whole link with no click ability. I dont want to show the whole link either.  would like to label the column and all the queryies show back as a link with just the word download.  You can see what i mean here http://scrsimracing.net/modules.php?name=RegisteredDrivers

    Where it says car skin  I want the links below there to show as a link that says download.  I used the admin panel to get the details to show in a page.  and linked it across with an <IFrame> couldnt get it to include in a module for it needs to query the use/ directory and it always says that it cant reach it and when i try to link to the data.dat file it says it doesnt exist.  anyway i just wanna turn that link into a clickable link and only show the word download.

     
    • TNTEverett

      TNTEverett - 2007-03-18

      This gets a little bit tricky because the file based data base treats all fields the same way.  It parses the data file and gets each line, then each field within a line.  These are all disaplyed juat as they were entered.  In order to display the link field as a hyperlink you must first parse each field and only treat teh link field as a link leaving all others to be displayed as they were entered. 

      For example:
      My index.php file displays this one line header and one line of stored data.

      FirstName LastName Email  Delete Record Printer Friendly
      Th Ev owner@tnt.com  delete Print

      The code to display this (the above display is missing the admin table structure graphics);
          for($j=0;$j<$i;$j++) {
            echo "<tr>";
            $holder = explode("|",$records[$j]);
            for ($k=0;$k<sizeof($holder);$k++) {
              echo "<td class='small'><center>$holder[$k]</td>";
            }
            echo "<td class='small'><center><a href='delete_file_rec.php?id=".$j."'>delete</a>";
            echo "<td class='small'><center><a href=\"printer_friendly.php?id=" . $j . "\">Print</a></tr>";
          }

      $i is the number of lines in the file.
      $j is the current line.
      $holder is an array of line items.
      $records is a previously generated array of lines from teh file.
      $k is the line item number.

      The file;
      FirstName|LastName|Email
      Th|Ev|owner@tnt.com

      So in the example I will display the email address as a clickable hyperlink using teh word "Download" (ignoring the fact that is an email address).
      The email address is item number 3 in each line. $j=0 just prints the first line of the file so I skip that line when adding my new display code.  $k=3 is the only item I want to display differently. 

          for($j=0;$j<$i;$j++) {
            echo "<tr>";
            $holder = explode("|",$records[$j]);
            for ($k=0;$k<sizeof($holder);$k++)
      //Start of new code
              if (($j>0)&&($k==3)) {
                echo "<td class='small'><center><A href=".$holder[$k].">Download</A></td>";
              }
              else
      //End of new code
                echo "<td class='small'><center>$holder[$k]</td>";
            }
            echo "<td class='small'><center><a href='delete_file_rec.php?id=".$j."'>delete</a>";
            echo "<td class='small'><center><a href=\"printer_friendly.php?id=" . $j . "\">Print</a></tr>";
          }

       
    • InTIM

      InTIM - 2007-03-18

      ok forgive me if this sounds stupid.  I may need to learn alot more about this.  But would I include the line of new code in my page that calls to the database from the website to report the records ? or would I include it in the process of the form?  Or do I even use that code ? was it just an example ?  here is my code for my website page that i made from the admin page.  I am sure it needs alot of cleaning.
      [code]
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <HTML><HEAD><TITLE>phpFormGenerator v2.0 Admin Portal</TITLE>
      <META http-equiv=Content-Type content="text/html; charset=windows-1252">
      <STYLE>
      P {
          PADDING-LEFT: 8px; FONT-SIZE: 12px; MARGIN: 10px; COLOR: #ffffff; LINE-HEIGHT: 18px; FONT-FAMILY: verdana, arial, "ms sans serif", sans-serif
      }
      .small {
          PADDING-LEFT: 10px; FONT-WEIGHT: normal; FONT-SIZE: 10px; COLOR: #ffffff; LINE-HEIGHT: 14px; FONT-FAMILY: verdana, arial, "ms sans serif", sans-serif
      }
      .big {
          PADDING-LEFT: 10px; FONT-SIZE: 14px; COLOR: #ffffff; LINE-HEIGHT: 14px; FONT-FAMILY: verdana, arial, "ms sans serif", sans-serif
      }
      TD {
          FONT-SIZE: 12px; COLOR: #333333; FONT-FAMILY: verdana, arial, "ms sans serif", sans-serif
      }
      A:link {
          FONT-WEIGHT: bold; COLOR: #333333; TEXT-DECORATION: none
      }
      A:visited {
          FONT-WEIGHT: bold; COLOR: #333333; TEXT-DECORATION: none
      }
      A:active {
          FONT-WEIGHT: bold; COLOR: #333333; TEXT-DECORATION: none
      }
      A:hover {
          FONT-WEIGHT: bold; COLOR: #666666; TEXT-DECORATION: overline
      }
      INPUT {
          PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 10px; PADDING-BOTTOM: 0px; COLOR: #333; PADDING-TOP: 0px; FONT-FAMILY: verdana, arial, sans-serif; BACKGROUND-COLOR: #eeeeee
      }
      TEXTAREA {
          PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 10px; PADDING-BOTTOM: 0px; COLOR: #333; PADDING-TOP: 0px; FONT-FAMILY: verdana, arial, sans-serif; BACKGROUND-COLOR: #eeeeee
      }
      SELECT {
          PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 10px; PADDING-BOTTOM: 0px; COLOR: #333; PADDING-TOP: 0px; FONT-FAMILY: verdana, arial, sans-serif; BACKGROUND-COLOR: #eeeeee
      }
      INPUT.button {
          BORDER-RIGHT: #999 2px outset; BORDER-TOP: #999 2px outset; BORDER-LEFT: #999 2px outset; BORDER-BOTTOM: #999 2px outset; BACKGROUND-COLOR: #ccc
      }
      </STYLE>

      </HEAD>
      <BODY bgColor=#333333>
      <CENTER>
                                     
        <TR>
          <TD><!----this is the bottom section where all the content goes----->
            <TABLE cellSpacing=0 cellPadding=1 bgColor=#ffffff border=0>
              <TBODY>
              <TR>
                <TD>
                  <TABLE cellSpacing=0 cellPadding=1 bgColor=#cccccc border=0>
                    <TBODY>
                    <TR>
                      <TD>
                        <TABLE cellSpacing=0 cellPadding=3 bgColor=white border=0>
                          <TBODY>
                          <TR>
                            <TD>
                              <TABLE cellSpacing=0 cellPadding=1 bgColor=#333333
                              border=0>
                                <TBODY>
                                <TR>
                                  <TD>
                                    <TABLE cellSpacing=0 cellPadding=3 width=510
                                    bgColor=#333333 border=0>
                                      <TBODY>
                                      <TR>
                                      <TD vAlign=top>&nbsp;</TD>
                                      <TD align=right><!----Item boxes for daily news events or whatever you want to talk about, i have included three.----->
                                      <TABLE>
                                      <TBODY>
                                      <TR>
                                      <TD>
                                      <TABLE cellSpacing=0 cellPadding=1
                                      <TD bgColor=#333333><font color="#FFFFFF">
                                      <TBODY>
                                      <TR>
                                      <TD>
      <TABLE cellSpacing=0 cellPadding=2 width=400 bgColor=#333333 border=0>
                                      <TBODY>
                                      <TR>
                                      <TD bgColor=#333333>
                                      <img border="0" src="header.jpg" width="400" height="100"></TD>
                                      <TD class=small align=right
                                      bgColor=#333333>&nbsp;</TD></TR>
                                      <!-- Put code here -->

      <?php
        include("./use/DriverRegistration/admin/config.inc.php");

        if ($db == 1) {
          echo "Using MySQL database info:<br><br>\n\n";
        } elseif ($file_db == 1) {
          echo "<br><br>\n";
        } else {
          echo "Sorry. In order to use the administration portal you must use the MySQL or file-based database option.\n\n";
        }

        if ($file_db == 1 && $db != 1) {
          $filedb = fopen("./use/DriverRegistration/admin/data.dat","r") or die ("<br>Could not open data file to read.");
          $columns_str = fgets($filedb,4096);
          $columns = explode("|",$columns_str);
          echo "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" width=\"90%\">\n";
          echo "<tr><td colspan=\"" . (sizeof($columns)+2) . "\">\n";
          echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">\n";
          echo "<tr><td class=\"small\" bgcolor=\"#000000\" align=\"center\" valign=\"middle\">\n";
          echo "<font color=\"#ffffff\">Records Table</td></tr></table></td></tr><tr>\n";

          for ($i=0;$i<sizeof($columns);$i++) {
            echo "<td class=\"small\"  align=\"center\" valign=\"middle\"><b>".$columns[$i]."</b></td>";
          }
          echo "<td class=\"small\" align=\"center\" valign=\"middle\"></td>";
          echo "<td class=\"small\" align=\"center\" valign=\"middle\"></td></tr>";

          $i=0;
          while (!feof($filedb)) {
            $temp = fgets($filedb,4096);
            if ($temp != "") {
              $records[$i]=$temp;
              $i++;
            }
          }
          if (($j>0)&&($k==3)) {
           echo "<td class='small'><center><A href=".$holder[$k].">Download</A></td>";
         }
      else 
          for($j=0;$j<$i;$j++) {
            echo "<tr>";
            $holder = explode("|",$records[$j]);
            for ($k=0;$k<sizeof($holder);$k++) {
              echo "<td class='small'><center>$holder[$k]</td>";
            }
            echo "<td class='small'><center><a href='delete_file_rec.php?id=".$j."'></a>";
            echo "<td class='small'><center>
          <p><a href=\"printer_friendly.php?id=" . $j . "\"></a></p>
          </tr>";
          }
          echo "</table>";
        } else if($db==1) {
          // mySQL Table
          $db_con = mysql_connect($hostname,$username, $password) or die("Connetion to database failed!");
          mysql_select_db($dbname);
          $query = "select * from ".$table;
          $result = mysql_query($query);
          $i = 0;

          while ($i < mysql_num_fields($result)) {
            $meta = mysql_fetch_field($result);
            $columns[$i] = $meta->name;
            $i++;
          }

          echo "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" width=\"90%\">\n";
          echo "<tr><td colspan=\"" . (sizeof($columns)+2) . "\">\n";
          echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">\n";
          echo "<tr><td class=\"small\" bgcolor=\"#000000\" align=\"center\" valign=\"middle\">\n";
          echo "<font color=\"#ffffff\">Records Table</td></tr></table></td></tr><tr>\n";

          for($i=1;$i<sizeof($columns);$i++) {
            echo "<td class='small'><center><b>".$columns[$i]."</td>";
          }
          echo "<td class='small'><center>
          <p></p>
          </td>\n";
          echo "<td class=\"small\" align=\"center\" valign=\"middle\"></td></tr>\n";

          $query = "select * from ".$table;
          $result = mysql_query($query);
          $j=0;

          while($row=mysql_fetch_array($result)) {
            echo "<tr>";

            for($i=1;$i<sizeof($columns);$i++) {
              echo "<td class='small'><center>".$row[$columns[$i]]."</td>";
            }

            $j=$row[$columns[0]];
            echo "<td class='small'><center><a href='delete_rec.php?id=".$j."'>delete</a></td>";
            echo "<td class='small'><center>
          <p><a href=\"printer_friendly.php?id=" . $j . "\"></a></p>
          </tr>";
          }
          echo "</table>";
        }

        // mySQL ends

      ?>
      <br /><br />
      </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR></TD></TR>
                                      </TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

      </center></form>

      </body></html>
      [code]

      If this is totaly wrong oops.  but this is the page that shows in my <IFRAME>. 

       
    • InTIM

      InTIM - 2007-03-19

      nevermind all that.  why is it file based and not mysql based ?  its getting info from the data.dat file right ?

       
      • TNTEverett

        TNTEverett - 2007-03-19

        Your admin page use/DriverRegistration/admin/index.php
        indicates you are using a file based database.  You set this up when you created the form.  This is why I gave you that example in the previous post.  If you think you should be using MySQL you need to start over, and then the code to do your display would be slightly different.  And, yes that was just example code.

         
    • InTIM

      InTIM - 2007-03-19

      ok got that fixed.  Sorry if i sounded rude or anything.  Thought I had told it to do from the database.  Guess now I need to start all over again.  Thanx for the help.  Is there anyway i can make this display back in a link now or was it easier with the file data.dat to make it like i wanted it ?

       
      • TNTEverett

        TNTEverett - 2007-03-19

        phpFormGenerator provides the basic form generation and prosessing.  With a little programming knowledge, there are literally hundreds of ways to do this.  Same thing with what you are asking for.  There literally hundres of ways to accomplish what you want to do.  Using phpFormGenerator is certainly one of them, but it will not do everything for you.  You have to know what you want before your get started.  When done with phpFormGenerator you will have to know how it works so you can modify it to suit your needs. 
        It sounds like you already have phpFormGenerator working properly to capture the data you want.  Does it really matter if it is MySQL or not?  You also have a way to display the data you have captured but you just want it in a different format.  Changing the format is not difficult but it does take some basic knowledge of php programming and of the data structure you are storing. 

         
    • InTIM

      InTIM - 2007-03-19

      ok well thanx for your help.  Thought u might know something to change simple to do this.  I will do some studying on this.  Its all a bit confusing when getting into variables and the language.  Was just looking for a simple quick fix.  Thanx again.

       
      • TNTEverett

        TNTEverett - 2007-03-20

        It could be quite simple but you have provided some confusing information. 
        Does your form use SQL or data file for a database? 
        From the admin it looks like the item number for the link is 4 (might be different if you use SQL).
        Depending on SQL or data file database the lines I gave you will work with only a slight modification. 
        It looks like you've also tried some changes since the last time I looked. 
        I'll help you if you wish but you'll have to be specific about details that I can only guess at without your input. 
        Lets try this; Create the form you want, tell me if it is SQL or file based, email me a copy of the index.php file and tell me exactly what changes you would like to see.  I'll make the change and send it back to you. 

         
    • InTIM

      InTIM - 2007-04-12

      Hey man sorry to bother ya again.  But from what we had been talking about I went and learned more php.  I finally got what I was wanting, here is a link to where you can view the page in action http://scrsimracing.net/modules.php?name=RegisteredDrivers .  Also here is the code I used to achieve this:

      [code]<?php
      #### Generated by Module Creator - By Disipal site (www.disipal.net) ####
      if (!eregi("modules.php", $PHP_SELF)) {
         die ("You can't access this file directly...");

      }
      require_once("mainfile.php");
      $module_name = basename(dirname(__FILE__));
      get_lang($module_name);
      include("header.php");
      $index = 0;
      OpenTable();
        
         // database information
         $host = '********';     
         $user = '********';
         $password = '********';
         $dbName = '********';
          echo"<div align=\"center\"><img src=\"phpform/header.jpg\" width=\"400\" height=\"100\"></div>";
         // connect and select the database
         $conn = mysql_connect($host, $user, $password) or die(mysql_error());
         $db = mysql_select_db($dbName, $conn) or die(mysql_error());
        
         // select all the entries from the table
         $sql = 'SELECT * FROM `drivers` LIMIT 0, 30 ';
         $result = mysql_query($sql, $conn) or die(mysql_error());

         // echo out the results to the screen
         while ($list = mysql_fetch_array($result)) {
            echo"<table width=\"100%\" height=\"100\" border=\"0\">"
        . " <tr>"
        . "   <td><b>Driver Name:   </b>{$list['Driver_Name']}<br>
                  <b>Driver Number: </b>{$list['Car_Number']}<br>
                  <b>Series:        </b>{$list['Series']}<br>
                  <b>Skin Picture:      </b><a target=\"_blank\" href={$list['Skin_Picture']}>View</a><br>
                  <b>Car Skin:      </b><a href={$list['Car_Skin']}>Download</a><br>
              <td><a target=\"_blank\" href={$list['Skin_Picture']}><div align=\"right\"><img src=\"{$list['Skin_Picture']}\" width=\"100\" height=\"100\" align=\"middle\">"
        . "</div>"
        . " </tr>"
        . "</table></br>";
         } // end while

         // echo out the form to add a new entry
        
      CloseTable();
      include("footer.php");

      ?>[/code]

      What I want to do is, when a user fills out a form and submits it, they don't have to upload a Car_Skin or a Skin_Picture.  I want to make the code I guess it would be an if statement, but make it look if there is a skin then report link like normal.  If there is not a file for the skin picture it will show a specified image that States ,  No Skin picture.  I will make the graphic i know,  I just want the script to check if there is a file and if there is then post it, if not then default to the image that says No Skin Picture.  I want it to check if there is a download link.  If there is post normally, If not then show Car Skin:{No File}.  If this is to much and I should go somewhere else let me know.  I know that this has nothing to do with the form.  By the way,  The form generator is awesome.  I have had no problems with it what so ever.  Installed with ease,  Great documentation also.  Thanx guyz for your hard work and dedication.  :)

       
      • TNTEverett

        TNTEverett - 2007-04-12

        Change the following portion of the code.

        while ($list = mysql_fetch_array($result)) {
              echo"<table width=\"100%\" height=\"100\" border=\"0\">"
          . " <tr>"
          . "   <td><b>Driver Name:   </b>{$list['Driver_Name']}<br>
                    <b>Driver Number: </b>{$list['Car_Number']}<br>
                    <b>Series:        </b>{$list['Series']}<br>";
              if ($list['Skin_Picture']) {
              echo"<b>Skin Picture:  </b><a target=\"_blank\"href={$list['Skin_Picture']}>View</a><br>";
                } else {
                echo "<b>Skin Picture:  </b>No Skin Picture<br>";
                }
              if ($list['Car_Skin']) { 
                echo "<b>Car Skin:      </b><a href={$list['Car_Skin']}>Download</a><br><td>";
            } else {
            echo "<b>Car Skin:      </b>No Download Available</a><br><td>";
            }
            if ($list['Skin_Picture']) {
                echo"<a target=\"_blank\" href={$list['Skin_Picture']}>
                <div align=\"right\">
                <img src=\"{$list['Skin_Picture']}\" width=\"100\" height=\"100\"align=\"middle\">"
                . " </div>";
                }
          echo
           " </tr>"
          . "</table></br>";
           } // end while

         
    • InTIM

      InTIM - 2007-04-15

      Thanx alot man.  That worked perfectly.  Hope one day to be as php savvy.  Thank you all again.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.