ziedinjsh Posted October 22, 2009 Report Share Posted October 22, 2009 šāds ir upload kods: if (isset($_POST['get_photo'])) { // faila detaljas $p_name = $_FILES["photo"]["name"]; $p_type = $_FILES["photo"]["type"]; $p_size = $_FILES["photo"]["size"]; $p_temp = $_FILES["photo"]["tmp_name"]; $p_error = $_FILES["photo"]["error"]; $p_date = date("Y-m-d"); if($p_error > 0) die ("photo culd not uploaded! Code: $p_error"); else { //Faila nosaciijumi if($p_type == "application/octet-stream" || $p_size >3145728) { die("this format is not allowed or file is to big"); } else { $query = mysql_query("INSERT INTO photos (p_name, p_type, p_size, p_date) VALUES ('$p_name','$p_type','$p_size','$p_date') "); move_uploaded_file($p_temp,"uploads/".$p_name); echo "photo uploaded!"; } } } echo "<form method='post' action='".$_SERVER['PHP_SELF']."' enctype='multipart/form-data'>"; echo "<input type='file' name='photo'>"; echo "<input type='submit' value='Upload' name='get_photo'>"; echo "</form>"; kā es varu piesaistīt augšupielādējamo bildi pie tā usera kas viņu augšupielādē useri atpazēst šādi: $result = mysql_query("SELECT * FROM users WHERE ID = '{$_SESSION['user_ID']}'"); Quote Link to comment Share on other sites More sharing options...
ohmygod Posted October 22, 2009 Report Share Posted October 22, 2009 izveido user_id kolonnu un aizpildi pie inserta ar current user_id Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 22, 2009 Author Report Share Posted October 22, 2009 nu tātad.. iekš photos izvdeoju user_id uztaisīju šādi: $user_id = $_SESSION['user_ID']; ievada datubāzē šādi: $query = mysql_query("INSERT INTO photos (p_name, user_id, p_type, p_size, p_date) VALUES ('$p_name', '$user_id', '$p_type','$p_size','$p_date') "); bilde augšupielādējas visi dati tiek ievadīti, bet user_id neievada. Kapēc tā? Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted October 22, 2009 Report Share Posted October 22, 2009 Skaties vai tev $user_id vai $_SESSION["user_ID"] vispār kaut ko satur. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 22, 2009 Author Report Share Posted October 22, 2009 nu kā $user_id būs tas kas ievadīs datubāzē tapēc ir šādi $user_id = $_SESSION['user_ID'] izdarot šādi: echo $_SESSION['user_ID']; tad lapā parādās user id Quote Link to comment Share on other sites More sharing options...
ohmygod Posted October 22, 2009 Report Share Posted October 22, 2009 izdrukā kveriju, ko izpildi. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 22, 2009 Author Report Share Posted October 22, 2009 (edited) tagad iet.. tagad sāku domāt kā tagad sanāk.. atverot profilu parādās username un email.. kā tagad izvadu bildi to kas katram ir users.php man izvada šādi $result = mysql_query("SELECT * FROM users ORDER BY id DESC"); bet kā lai uztaisa lai izvadītu arī informāciju no $result = mysql_query("SELECT * FROM photos "); ??? Edited October 22, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted October 22, 2009 Report Share Posted October 22, 2009 Esi dzirdējis tādu lietu? SELECT * FROM photos WHERE user_id = $id Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 22, 2009 Author Report Share Posted October 22, 2009 (edited) jā es esmu, bet kad man atrodas divi SELECT * FROM vienā lapā tad man vai nu viens vai otrs neiet.. nelasa infomāciju! cik sakarīgs ir šāds variants? $result = mysql_query("SELECT * FROM users, photos ORDER BY id DESC"); Edited October 22, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted October 22, 2009 Report Share Posted October 22, 2009 Tad meklē kļūdu kādēļ neiet nevis domā jocīgus risinājumus - vaina noteikti ir tavā kodā. Un tavs variants ir nesakarīgs. Tu vari JOIN`ot tabulas kopā: SELECT users.*, photos.* FROM users INNER JOIN photos ON users.id = photos.user_id WHERE photos.user_id = $id Protams viņu vajag pieslīpēt tavām vajadzībām. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 22, 2009 Author Report Share Posted October 22, 2009 nu jā.. <?php include "misc/config.php"; include "header.php"; include "left.php"; $result = mysql_query("SELECT users.*, photos.* FROM users INNER JOIN photos ON users.id = photos.user_id WHERE photos.user_id = id ORDER BY id DESC"); if (isset($_POST['yes'])) { mysql_query("UPDATE users SET yes = yes +1 WHERE id='id'"); } elseif (isset($_POST['no'])) { mysql_query("UPDATE users SET no = no +1 WHERE id='id'"); } while($data = mysql_fetch_array($result)) { echo "<table><tr>"; echo "<td>username</td><td>".$data['username']."</td>"; echo "</tr><tr>"; echo "<td>email</td><td>".$data['email']."</td>"; echo "</tr><tr>"; echo "<td>bilde</td><td><img src='photos/big/".$data['p_name']."' width='100'></td>"; echo "</tr><tr>"; echo "<td>do you like?</td><td>"; echo "<form method='post'><input type='submit' name='yes' value='yes' /></form>"; echo "<form method='post'><input type='submit' name='no' value='no' /></form>"; echo "</td>"; echo "</tr></table>"; echo "<hr>"; } include "footer.php"; ?> no visiem lietotājiem man rādās tikai viens Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted October 22, 2009 Report Share Posted October 22, 2009 Es jau teicu, ka tev vajadzēs viņu pārtaisīt, lai darbojas kā tev vajag. Iztūlko, ko nozīmē WHERE un padomā ko vajadzētu darīt. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.