Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 07-01-2003, 01:41 AM
Elem Elem is offline
 
Join Date: Sep 2002
Location: Sunny Southern California
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default In need of some mysql help

I could really use some help on this problem i can't get around....and with my limited knowledge of mysql this is causing some problems

Ok i guess i should start off with what i'm trying to do. I have made a file uploader. Now what i want to do is when the user ventures to the upload area it shows them a link for each uploaded file. Also i should mention the script is being run from within vb...so it is using vb's db.

Here's what i currently have
PHP Code:
$showpic $DB_site->query("SELECT uploadname FROM user ORDER BY uploadname DESC");
$picname $DB_site->fetch_array($showpic);

$upload_bits="";

$piccount $DB_site->num_rows($showpic);
if (
$piccount == 0) {
eval (
"\$upload_bits .= \"".gettemplate("upload_none")."\";");
} else {
      eval (
"\$upload_bits .= \"".gettemplate("upload_isthere")."\";");

uploadname is a column i have added to the users table. Upload_none template says there are no pics...and the Upload_isthere template is supposed to show the links

once an image is uploaded this is the query i'm using
PHP Code:
$DB_site->query("INSERT INTO user (uploadname) VALUES ('$imname')"); 
$imname is $_FILES['userfile']['name']

Upload_isthere looks like this
PHP Code:
<a href="$shorturl/$picname[uploadname]">$shorturl/$picname[uploadname]</a
As it is right now...it only shows the file that was last uploaded...nothing more..even though there are 2 images in the db

So my question is how do i get it to display all of the images uploaded?

Also how do i get it so it only shows the pics uploaded by that person only?

I really appreciate any help...since this is my first hack from scratch and i'm really lost :P
Reply With Quote
  #2  
Old 07-01-2003, 02:23 AM
Cloudrunner's Avatar
Cloudrunner Cloudrunner is offline
 
Join Date: May 2003
Location: Butte, MT
Posts: 635
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
unset($upload_bits); //clears the variable
$showpic $DB_site->query("SELECT uploadname FROM user WHERE userid = '".$bbuserinfo['userid']."' ORDER BY uploadname DESC"); //sets the query, and only shows uploads from user viewing page.
if ($DB_site->num_rows($showpic) == 0){ //check for number of rows, if none, then display error page
    
eval("standarderror(\"".gettemplate("upload_none")."\");"); //provides an error page with redirect
} else { //or else display downloads page
    
while($picname $DB_site->fetch_array($showpic)); //loop until last row in table
      
$picname $picname['uploadname']; //You will have to call this variable ($picname) in the template 'upload_isthere' for it to show up in the template
        
eval ("\$upload_bits .= \"".gettemplate("upload_isthere")."\";"); //setup the variable to display the template
    
// close the while statement
    
eval("dooutput(\"".gettemplate('upload_index')."\");"); //change upload_index to the template for the actual display of the page this page would need to use the variable $upload_bits
//close the if statement 
Hope that helps, follow the comments and you should see the steps.
Reply With Quote
  #3  
Old 07-01-2003, 02:55 AM
Elem Elem is offline
 
Join Date: Sep 2002
Location: Sunny Southern California
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hey thanks for your help...although it's not quite fully working yet

now on the page is it just showing the url once...without the filename attached.

this is the current upload_ishere
PHP Code:
<tr><td bgcolor="{tableheadbgcolor}" colspan="2"><normalfont color="{tableheadtextcolor}" class="thtcolor"><a href="$shorturl/$picname">$shorturl/$picname[uploadname]</a></normalfont></td></tr
this is the template which is the index for the hack...i apologize for it being long but it is the full thing incase there is an issue with it

PHP Code:
{htmldoctype}
 <
html>
 <
head>
 <
title>$bbtitle $username's Picture Upload</title>
 $headinclude
 </head>
 </html>
     <body> 
    $header
    <!-- breadcrumb -->
<table bgcolor="{pagebgcolor}" class="bordert" border="0" width="{tablewidth}" cellpadding="0" cellspacing="0">
<tr><td>

<table cellpadding="2" cellspacing="0" border="0" width="{contenttablewidth}" {tableinvisibleextra} align="center">
<tr>
    <td><img src="{imagesfolder}/vb_bullet.gif" align="middle" alt="vBulletin">
    <normalfont><b><a href="index.php?s=$session[sessionhash]">$bbtitle</a> &gt; 
    Photo upload for $bbuserinfo[username]</b></normalfont></td>
    <td align="right">$forumjump</td>
</tr>
</table>
<!-- /breadcrumb -->
<br>
$cpnav
<br>


<form enctype="multipart/form-data" action="test.php" method="post">


<table cellpadding="{tableouterborderwidth}" cellspacing="0" border="0" bgcolor="{tablebordercolor}" {tableouterextra} width="{contenttablewidth}" align="center"><tr><td>
<table cellpadding="4" cellspacing="{tableinnerborderwidth}" border="0" {tableinnerextra} width="100%">
<tr>
    <td bgcolor="{tableheadbgcolor}" colspan="2"><normalfont color="{tableheadtextcolor}" class="thtcolor"><b>Upload - $bbuserinfo[username]</b></normalfont></td>
</tr>

$upload_bits

<tr>
    <td bgcolor="{firstaltcolor}"><normalfont><b>Upload:</b></normalfont></td>
    <td bgcolor="{firstaltcolor}"><normalfont><input name="userfile" type="file"></normalfont>
</td>
</tr>
</table>
</td></tr></table>

<br>

<table cellpadding="2" cellspacing="0" border="0" width="{contenttablewidth}" {tableinvisibleextra} align="center">
<tr>
    <td align="center"><normalfont>
    <input type="hidden" name="action" value="upload">
<input type="submit" value="Upload">
    </normalfont></td>
</tr>
</table>

</form>

$footer

</body>
</html> 
thanks for all your help
Reply With Quote
  #4  
Old 07-01-2003, 04:46 AM
Cloudrunner's Avatar
Cloudrunner Cloudrunner is offline
 
Join Date: May 2003
Location: Butte, MT
Posts: 635
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

upload_ishere:

Code:
<tr>
  <td bgcolor="#1D6AA0" colspan="2">
    <normalfont color="#EEEEFF" class="thtcolor">
      <a href="$bburl/$picname">$bburl/$picname</a>
    </normalfont>
  </td>
</tr>
unless of course $shorturl is defined in the script elsewhere it would be best to use $bburl/path/$picname...

upload_index:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>$bbtitle - $bbuserinfo[username]'s Picture Upload</title>
$headinclude
</head>
</html>
<body>
$header
<!-- breadcrumb -->
<table bgcolor="#0E3652" class="bordert" border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td>
      <table cellpadding="2" cellspacing="0" border="0" width="95%" align="center">
        <tr>
          <td>
            <img src="https://vborg.vbsupport.ru/images/vb_bullet.gif" align="middle" alt="vBulletin">
            <normalfont>
              <b><a href="index.php?s=$session[sessionhash]">$bbtitle</a> &gt;
              Photo upload for $bbuserinfo[username]</b>
            </normalfont>
          </td>
          <td align="right">
            $forumjump
          </td>
        </tr>
      </table>
      <!-- /breadcrumb -->
      <br>
      $cpnav
      <br>
      <form enctype="multipart/form-data" action="test.php" method="post">
      <table cellpadding="0" cellspacing="0" border="0" bgcolor="#0A293E" width="95%" align="center">
      <tr>
        <td>
          <table cellpadding="4" cellspacing="1" border="0" width="100%">
            <tr>
              <td bgcolor="#1D6AA0" colspan="2">
                <normalfont color="#EEEEFF" class="thtcolor">
                  <b>Upload - $bbuserinfo[username]</b>
                </normalfont>
              </td>
            $upload_bits
              <td bgcolor="#13486D">
                <normalfont>
                  <b>Upload:</b>
                </normalfont>
              </td>
              <td bgcolor="#13486D">
                <normalfont>
                  <input name="userfile" type="file">
                </normalfont>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    <br>
    <table cellpadding="2" cellspacing="0" border="0" width="95%" align="center">
      <tr>
        <td align="center">
          <normalfont>
            <input type="hidden" name="action" value="upload">
            <input type="submit" value="Upload">
          </normalfont>
        </td>
      </tr>
    </table>
    </form>
$footer 
</body> 
</html>
Do a side by side file compare using beyond compare2 (or equivalent) and you'll see where I made the changes...Basically the reason your link would show only once is that you had two table rows defined one after another...no good...also, make sure that the userid is the same in both items....

Now, one thing, if you are using the user table to define the upload pics, then you would be better off using the uploadname field as an id to query off another table that has the filename stored...that way each user can have multiple uploads. The way it is setup now will only allow one upload per user. The reason is that each user only uses one row in the table, thus only allowing one piece of data per field. Thus, the new query that I provided you will only show one field.

If you want, we can hook up this weekend via any of the messengers listed in my profile and we can walk through the code abit and see what we can do with it...but for now without more background on the hack, I canna help any more than what I have done here.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:08 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03620 seconds
  • Memory Usage 2,230KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete