For example, if we need the database selection function for the contacts page, then it can be done as follows:
function the_name_contact($param) { $result = mysql_query("SELECT * FROM contacts"); if ($param == "title") { while ($row = mysql_fetch_assoc($result)) { echo $row['name']; } } elseif ($param == "email") { while ($row = mysql_fetch_assoc($result)) { echo $row['email']; } } elseif ($param == "address") { while ($row = mysql_fetch_assoc($result)) { echo $row['address']; } } }; the function returns nothing. It has the $ param parameter and if I need to display a specific field with a database in the value attribute (this is necessary for the admin to see the value of the field) or just output to any tag on the site in the right place, then I can write it like <?php the_name_contact('email'); ?> <?php the_name_contact('email'); ?> call the function with the email parameter which is equal to the email field in the database. And if I need, for example, I need the function to select the database page with the slider of stores, where there is a name and description. Here is a slightly different structure:
$main_menu = get_stores(); function get_stores() { $result = mysql_query("SELECT * FROM stores"); while ($row = mysql_fetch_array($result)) { $count++; $res_array[$count] = $row; } return $res_array; } I did this script by example, and here I am a little confused. There is a get_stores() function in which a loop is being sampled. and here we are not declaring a function, but returning a value, why so? And it is not clear why $count++ ; In the previous script there was no increment, why is it here? This $res_array[$count] = $row; is also not clear $res_array[$count] = $row; With this done, now you need to loop out the slides, I do it through foreach.
<?php foreach ($our_stores as $stores): ?> <a href="portfolio.php?type=stores&id=<?=$stores['id'] ?>"><h3 class="title"><?= $stores['title']?></h3></a> <p class="desc"> <?= $stores['address']?> </p> <?php endforeach; ?> Here everything is displayed on the site using the variable <?= $stores['title']?> Which has an array and its index is a field from the database, everything is fine here. But I have a form in the admin which adds, edits and deletes slides. And the problem is that I can’t put any value in the value field on the slide editing page, like <?= $stores['title']?> But it only works in this foreach loop. And in the admin foreach I do not need. I already broke my head, I can't figure out how to display the value on the slide editing page? In the first example, with the the_name_contact() function and the $ param parameter, everything is simple, but it doesn't work that way.