NERVi Posted July 10, 2012 Report Share Posted July 10, 2012 (edited) Ko es daru nepareizi? <?php require_once 'connect.inc.php'; $query = "SELECT `id` FROM `categorys`"; $query_run = mysql_query($query); for($field = 1;$field <= mysql_num_rows($query_run);$field++){ $query2 = "SELECT `title` , `link` FROM `categorys` WHERE `id` = '$field'"; if( $query2_run = mysql_query($query2)){ $query_title = mysql_result($query2_run,`title`); $query_link = mysql_result($query2_run,`link`); echo $query_title." Link: ".$query_link."<br>"; } } ?> Tabula izskatās šādi: Galarezultātam jābūt šādam: category1 Link: http://lol.com category2 Link: http://lol2.com category3 Link: http://lol2.com category4 Link: http://lol3.com Bet ir šāds: category1 Link: category1 category2 Link: category2 category3 Link: category3 category4 Link: category4 Edited July 10, 2012 by NERVi Quote Link to comment Share on other sites More sharing options...
waplet Posted July 10, 2012 Report Share Posted July 10, 2012 (edited) pareizāk būtu.. $query = "SELECT name, link FROM categorys"; $query = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($query)){// vai mysql_fetch_assoc echo $row['name']." link: <a href='".$row['link']."'>link</a>"; } Un jā, vēl tad varētu iesaistīt, mysql num rows un tml.. Edited Edited July 11, 2012 by waplet Quote Link to comment Share on other sites More sharing options...
NERVi Posted July 10, 2012 Author Report Share Posted July 10, 2012 (edited) pareizāk būtu.. $query = "SELECT name, link FROM categorys"; $query = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_row($query)){ echo $row['name']." link: <a href='".$row['link']."'>link</a>"; } Un jā, vēl tad varētu iesaistīt, mysql num rows un tml.. Nospiežot uz linka, netiek redirektots uz citu lapu.Paliek tajā pašā lokalhostā Edited July 10, 2012 by NERVi Quote Link to comment Share on other sites More sharing options...
waplet Posted July 10, 2012 Report Share Posted July 10, 2012 (edited) $query = "SELECT `name`, `link` FROM `categorys`"; btw, parādi visu failu. Edited July 10, 2012 by waplet Quote Link to comment Share on other sites More sharing options...
NERVi Posted July 10, 2012 Author Report Share Posted July 10, 2012 (edited) $query = "SELECT `name`, `link` FROM `categorys`"; btw, parādi visu failu. <?php require_once 'connect.inc.php'; $query = "SELECT `name`, `link` FROM `categorys`"; $query = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_row($query)){ echo $row['name']." link: <a href='".$row['link']."'>link</a>"; } ?> Edited July 10, 2012 by NERVi Quote Link to comment Share on other sites More sharing options...
waplet Posted July 10, 2012 Report Share Posted July 10, 2012 Nu, kur links redirektē ir jaskatās, ko viņs izvelk laukā un tml... vai pareizi esi datus savadījis, šitais "jau tikai darbinieks ,kas parāda, ko kāds cits dara, nevis pats atbild par viņu darbu(html'u)" Quote Link to comment Share on other sites More sharing options...
NERVi Posted July 10, 2012 Author Report Share Posted July 10, 2012 (edited) Nu, kur links redirektē ir jaskatās, ko viņs izvelk laukā un tml... vai pareizi esi datus savadījis, šitais Esmu visu pareizi savadījis Lapas source: link: <a href=''>link</a> link: <a href=''>link</a> link: <a href=''>link</a> link: <a href=''>link</a> Šobrīd lapas kods izskatās šādi: <?php require_once 'connect.inc.php'; $query = "SELECT `name`, `link` FROM `categorys`"; $query = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_row($query)){ echo $row['name']." link: <a href='".$row['link']."'>link</a><br>"; } ?> Datubāze: CREATE TABLE `categorys` ( `id` int(11) NOT NULL auto_increment, `name` varchar(30) NOT NULL, `link` varchar(40) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; -- -- Dumping data for table `categorys` -- INSERT INTO `categorys` VALUES (1, 'category1', 'http://lol.com'); INSERT INTO `categorys` VALUES (2, 'category2', 'http://lol2.com'); INSERT INTO `categorys` VALUES (3, 'category3', 'http://lol3.com'); INSERT INTO `categorys` VALUES (4, 'category4', 'http://lol4.com'); Edited July 10, 2012 by NERVi Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted July 11, 2012 Report Share Posted July 11, 2012 (edited) Kļuda ir iekš: while($row = mysql_fetch_row($query)) ja izmanto šo tad tiek izveidots nevis asocaitivais masīvs bet parastais $row[0]." link: <a href='".$row[1]."'>link</a><br>"; tadēļ labāk izmantot : mysqli_fetch_array() tad varēsi izmantot abus izvades varjantus - ātrdarbības zaudējums būs tik niecīgs, ka pie maziem datu apjomiem - faktiski nebūs izmērāms Edited July 11, 2012 by Grey_Wolf Quote Link to comment Share on other sites More sharing options...
Kavacky Posted July 11, 2012 Report Share Posted July 11, 2012 Pēc datubāzes idejas kā tādas, indeksu izmantošana kolonnu nosaukumu vietā vispār ir kļūda. Quote Link to comment Share on other sites More sharing options...
Mr.Key Posted July 23, 2012 Report Share Posted July 23, 2012 Pēc datubāzes idejas kā tādas, indeksu izmantošana kolonnu nosaukumu vietā vispār ir kļūda. Kādas mulķības? Pat SQL paredz izmantot indeksus nosaukumu vietā. Ceru, ka šis nebūs jaunatklājums... 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.