mjc66 Posted October 9, 2007 Report Share Posted October 9, 2007 Пытаюсь написать скрипт вывода из БД всех имеющихся групп товаров и соответствующим им количества наименований. Собственно задача не самая сложная и результат удовлетворительный, однако не получается сделать переадресацию по ссылке на страницу, где эта группа находится. Ссылкой является название группы товаров. Вот сам скрипт: <?php//соединение с БДinclude "config_mysql.php";//переменные:$page =isset($_GET['State_Standard_Samples.php']);$page =isset($_GET['Aromatic_substances.php']);$page =isset($_GET['Indicators_dyes.php']);$page =isset($_GET['Display_tubes.php']);$page =isset($_GET['Laboratory_glass/Areometers.php']);$page =isset($_GET['Laboratory_glass/General_purpose_products.php']);$page =isset($_GET['Laboratory_glass/Measured_products.php']);$page =isset($_GET['Laboratory_glass/Devices_and_devices.php']);$page =isset($_GET['Laboratory_glass/Miscellaneous.php']);$page =isset($_GET['Laboratory_glass/Thermometers_household.php']);$page =isset($_GET['Laboratory_glass/Thermometers_technical.php']);$page =isset($_GET['Nutrient_mediums_for_microbiology.php']);$page =isset($_GET['Solvents.php']);$page =isset($_GET['Standards_credits.php']);$page =isset($_GET['Container_packing.php']);$page =isset($_GET['Technical_production.php']);$page =isset($_GET['Fabrics_technical.php']);$page =isset($_GET['Refractory_substances.php']);$page =isset($_GET['Filters.php']);$page =isset($_GET['Chemical_reactants.php']);$page =isset($_GET['Pure(Clean)_substances_for_a_chromatography.php']);?><table border='1' cellspacing='0' cellpadding='1'> <tr> <td width='80%' align='center'> <b>Группа товаров:</b> </td> <td width='20%' align='center'> <b>Кол-во наименований:</b> </td> </tr><?php$result = mysql_query("SELECT group_production, COUNT(*) FROM `tovary` GROUP BY group_production ");while ($t = mysql_fetch_array($result)) {print('<tr> <td><a href=$ >'.$t['group_production'].'</a></td> <td>'.$t['COUNT(*)'].'</td> </tr>');}print('</table>');?></table> В настоящий момент передается не значение переменной $ , а само вырыжение $ . Link to comment Share on other sites More sharing options...
Darhazer Posted October 10, 2007 Report Share Posted October 10, 2007 (edited) Вам надо прочитать про разнице м/у ' и " :-) Еще, у вас переменная $ нету ( и не можеть быть ), у вас есть $page который лыбо true лыбо false, так что уточните пожалуйста чего хотите передать в href ? Можеть быть вот так... Заменяем print('<tr> <td><a href=$ >'.$t['group_production'].'</a></td> <td>'.$t['COUNT(*)'].'</td></tr>'); на print('<tr> <td><a href="'.str_replace(' ', '_', $t['group_production']).'.php">'.$t['group_production'].'</a></td> <td>'.$t['COUNT(*)'].'</td></tr>'); Edited October 10, 2007 by Darhazer Link to comment Share on other sites More sharing options...
mjc66 Posted October 10, 2007 Author Report Share Posted October 10, 2007 В href нужно передать адреса (названия файлов), которые я вбивал для $page. Link to comment Share on other sites More sharing options...
Darhazer Posted October 10, 2007 Report Share Posted October 10, 2007 Вообщем для $page вы вбили "false" ( если неверите добавите var_dump( $page ) ) Правильно будет вот так: <?php//соединение с БДinclude "config_mysql.php";//переменные:$pages[ 'State Standard Samples'] = 'State_Standard_Samples.php';$pages[ 'Areometers'] = 'Laboratory_glass/Areometers.php;//и т.д. для всех остальних?><table border='1' cellspacing='0' cellpadding='1'> <tr> <td width='80%' align='center'> <b>Группа товаров:</b> </td> <td width='20%' align='center'> <b>Кол-во наименований:</b> </td> </tr><?php$result = mysql_query("SELECT group_production, COUNT(*) FROM `tovary` GROUP BY group_production ");while ($t = mysql_fetch_array($result)) {print('<tr> <td><a href="'.$pages[ $t['group_production'] ].'">'.$t['group_production'].'</a></td> <td>'.$t['COUNT(*)'].'</td></tr>');}print('</table>');?></table> Еще можно их в БД записать Link to comment Share on other sites More sharing options...
mjc66 Posted October 10, 2007 Author Report Share Posted October 10, 2007 Огромный респект! Link to comment Share on other sites More sharing options...
mjc66 Posted October 10, 2007 Author Report Share Posted October 10, 2007 Довольно странный я получил результат, для каждой группы товаров предупреждение типа: Notice: Undefined index: Растворители in C:\apache\test.ru\www\The_catalogue_of_the_goods.php on line 126 Вот эта строка <td>><a href="'.$pages[ $t['group_production'] ].'">'.$t['group_production'].'</a></td> А при наведении на ссылку в строке состояния браузера кроме www.test.ru/ далее ничего Link to comment Share on other sites More sharing options...
Darhazer Posted October 10, 2007 Report Share Posted October 10, 2007 Все написано же... из БД вы получаете Растровители но в начале скрипта вы не определили $pages[ 'Растворители' ] и он не знаеть на какой странице находиться ваш товар Link to comment Share on other sites More sharing options...
mjc66 Posted October 10, 2007 Author Report Share Posted October 10, 2007 Еще раз респект-разобрался окончательно! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now