虽然循环不能在PHP中工作

时间:2016-08-27 03:48:10

标签: php

虽然循环不起作用但没有显示任何内容。

当我在同一页面上没有创建函数的情况下使用我的代码时,但是当我在functions.php上创建函数并调用它时,它不起作用。

<?php 
include "include/db.php";

function search(){
    global $connection;
    $record_search = $_GET['search'];
    $record_search = mysqli_real_escape_string($connection, $record_search);

    $query_search = "SELECT * FROM users WHERE u_name='$record_search' OR       u_roll='$record_search' ";
    $result_search = mysqli_query($connection, $query_search);
    if(!$result_search){
        die("FAIL" . mysqli_error($connection));
    }
    while ($row_search = mysqli_fetch_array($result_search)) {
        $name_search     =      $row_search[1];
        $f_search        =      $row_search[2];   
        $school_search   =      $row_search[3];
        $roll_search     =      $row_search[4];
        $email_search    =      $row_search[5];
        $class_search    =      $row_search[6];
    }
}
?>

<?php 
if(isset($_GET['search'])){
        global $connection;
        global $result_search;
        search();
        ?>
<table class="table">
  <thead>
   <thead>
        <tr>
            <th>#</th>
            <th>First Name</th>
            <th>Father Name</th>
            <th>School</th>
            <th>Roll No</th>
            <th>Email</th>
            <th>Class</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th scope="row">1</th>
            <td><?php echo @$name_search; ?></td>
            <td><?php echo @$f_search; ?></td>
            <td><?php echo @$school_search; ?></td> 
            <td><?php echo @$roll_search; ?></td> 
            <td><?php echo @$email_search; ?></td> 
            <td><?php echo @$class_search; ?></td>     
        </tr>   
       <?php }  ?>
  </tbody>
</table>

你看不到任何事情:

2 个答案:

答案 0 :(得分:0)

您是否尝试在执行查询之前连接到mysql。也许,你把连接代码放在另一个文件中,但是在这里看不到它只是想知道。

答案 1 :(得分:0)

您的代码应如下所示,希望它对您有用。

<TabControl x:Name="tabControl" HorizontalAlignment="Left" Height="311" Margin="0" VerticalAlignment="Top" Width="717" Background="#FFF9F9F9" Style="{DynamicResource MainMenuTabs}">
  <TabItem Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}">
        <!-- TAB 1 -->
        <TabItem.Header>
              <Grid x:Name="Main" Margin="0" Height="52" Width="166">
                    <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="52"/>
                          <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock x:Name="textBlock" Margin="0,5,0,3" TextWrapping="Wrap" Foreground="White" FontSize="36" Grid.Column="1" d:LayoutOverrides="Width" VerticalAlignment="Bottom"><Run Text="Main"/></TextBlock>
                    <Image x:Name="icons_server_32_png" Margin="10,0,10,10" Source="icons/server-32.png" Stretch="Fill" Height="32" VerticalAlignment="Bottom"/>
              </Grid>
        </TabItem.Header>
        <Grid Background="#FFE5E5E5"/>
  </TabItem>
  <TabItem>
        <!-- TAB 2 -->
        <TabItem.Header>
              <Grid x:Name="Backups" Margin="0" Height="52" Width="216">
                    <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="52"/>
                          <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock x:Name="textBlock1" Margin="0,5,0,3" TextWrapping="Wrap" Foreground="White" FontSize="36" Grid.Column="1" d:LayoutOverrides="Width" VerticalAlignment="Bottom" Text="Backups"/>
                    <Image x:Name="icons_server_32_png1" Margin="10,0,10,10" Source="icons/magnifier-tool.png" Stretch="Fill" Height="32" VerticalAlignment="Bottom"/>
              </Grid>
        </TabItem.Header>
        <Grid Background="#FFE5E5E5"/>
  </TabItem>
</TabControl>